I am having application deployed in the URL
HOST_NAME/abc/appname/login.action
and when using Struts 2 URL tag
<s:url id="testURL" action="login">
</s:url>
am getting
HOST_NAME/appname/login.action
instead of
HOST_NAME/abc/appname/login.action
How to get the abc in path in the URL without hardcoding it?
Hi Hariharan
Change the namespace defined in your struts.xml file.
Instead of namespace="/" use namespace="/abc".
This will redirect your actions to the desired path and I hope this will help you.
Related
We're using Struts 2 in our web application. There are bunch of action mappings defined already, I want to implement a feature where any Urls starting with /buy and not mapped to any of the existing action mappings e.g. /buy/new or buy/old should be redirected to buy/index action. For example if someone is trying to go to /buy/bla1 or /buy/bla2 or buy/bla1/bla2/bla3 should go to buy/index.
Define the following action in your /buy package:
<action name="*">
<result type="redirectAction">index</result>
</action>
Alternatively you can just use:
<default-action-ref name="index" />
But then you will get no redirect. Instead the index page will show under the nonexisting address.
You also need to set the following parameter in your struts.properties:
struts.action.extension = action,,
You can add other extensions to the parameter, but as far as i know there is no wildcard for all extensions. The blank string covers directories like /buy/bla but /buy/bla.x won't be covered and will produce a 404 error unless you add x to the list of extensions.
If this is not good enough you might be better off solving this by using redirect rules in the webserver.
You can use default action reference and provide a JSP success path to it.
If any unmatched action is received then it will call the given action and forward it to the result JSP page.
I'm working with struts2.
An external app calls to my app with url
http://localhost:8080/present/jsp/mi.action?cod=02021
But because of my JSP file system, my action result is in
http://localhost:8080/present/jsp/ALTE/mi.action?cod=02021
(note the difference in ALTE).
The JSP has some lines as
<%# include file="../comuns/comunCssyJs.jsp"%>
The first ../ is to go out ALTE.
If I access with first link the page is loaded but no include files are found. However, with second link there is no problem.
Does someone know what can I do? I know I can change my JSP-s dir-s, but I'd prefer to "add automatically" the ALTE path to the url. is that possible?
Thanks in advance.
Jon
Use Struts2 <s:include> tag http://struts.apache.org/2.x/docs/include.html with <s:url> tag http://struts.apache.org/2.x/docs/url.html.
I have a Struts2 app and I'm having a bit of a problem:
at the first page (index.jsp) I have a javascript line that sets the url to './admin/Search' like this:
window.location='./admin/Search';
that sends me to the login page and if I have access it will redirect me directly to the mentioned page. The problem is that, after that, all my actions keep this first namespace '/admin'. Other actions just do not have this '/admin' namespace, for example, they could have a '/users' namespace. In this cases the server can't locate the right action because it will look for /admin/myAction in the struts.xml file. It's like struts 2 doesn't change the whole namespace/action. It just replaces the action and that's it. I really need help on this guys! Thanks.
You need to change the package namespace specified in the in struts.xml files. That will help you redirect your namespace inside your application.
What I need is to add an prefix (such as 'secure') for all urls which requires login, is it possible for Seam url rewriting to do this:
<page view-id="/view/*" login-required="true">
<rewrite pattern="/{prefix}/{url}" />
</page>
<page view-id="/view/home.xhtml">
<rewrite url="/home"/>
</page>
I don't think this would work, since it is ambigious view/* matches also view/home . In a similar situation I moved all pages to view/secure and forced login on these view-ids.
With an editor which supports global search/replace you can quickly change the references between pages.
How to implement pagination in grails portlet on Liferay.
The basic pagination was not working on Liferay. When clicked on next the page is jumping from Liferay url to normal url
I used like this :
<g:paginate next="Forward" prev="Back"
maxsteps="10" controller="book"
action="list" total="${Book.count()}" />
thanks in advance.
The normal pagination tag won't work inside a portlet, you'll need to copy the tag code and modify it to post to the actionURL of your portlet (call the jsp tag provided by the portal to get this url from your gsp tag code), instead of the default url for the controller.
I've never done this myself, someone else my be able to post some example code.
cheers
Lee