You are viewing a plain text version of this content. The canonical link for it is here.
Posted to user@struts.apache.org by Ben Taylor <be...@gmail.com> on 2005/02/28 02:44:19 UTC
RequestURI (Action not JSP)
Can anyone tell me if it is possible to extract the name of the
current action from within a JSP? ie. /welcome.do, or
/secure/login.do... Is there a tag that can do this - maybe within
one of the additional tag libraries?
Thank you in advance.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: RequestURI (Action not JSP)
Posted by Tim Christopher <ti...@gmail.com>.
Hi,
I'd like to be able to access the path of my Struts Action as the
Display Tag requires a parameter 'requestURI'. It needs this
attribute so that it can append values to the end of the current url -
without the requestURI it will make the link point to the jsp which is
located under the WEB-INF directory.
The best way I can think of doing this is to extend the
RequestProcessor to add request.getRequestURI() as a variable stored
in each request. I will then access like this within a JSP:
<% String a = (String) request.getAttribute("actionName"); %>
<display:table name="somecollection" requestURI="<%= a %>">
<display:column property="id" sortable="true"></display:column>
</display:table>
I don't seem to be able to extract it within the display:table tag
itself, no matter how I nest different "s and 's... However as tables
are only on a relatively small number of pages I'm not sure this is
the best way, also it looks a bit clumsy,
Any suggestions?
Tim Christopher
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: RequestURI (Action not JSP)
Posted by Erik Weber <er...@mindspring.com>.
I used something like this once.
First I extended RequestProcessor. I picked the processActionPerform
method because it's one of the last ones to be invoked by the
controller, and various attributes tend to get removed/added as the
controller moves through the request processing chain. Sometimes it's
helpful to override two and compare. Don't forget you have access to the
source, too, but I think this is quicker. Don't forget to invoke super
when you override these methods. Also you could do this with a filter I
suppose. Also you could do it in a scriplet in a JSP.
public class MyRequestProcessor extends
org.apache.struts.action.RequestProcessor {
public ActionForward processActionPerform(HttpServletRequest request,
HttpServletResponse response, Action action, ActionForm form,
ActionMapping mapping) {
//do what would be done by default
ActionForward forward = super.processActionPerform(request, response,
action, form, mapping);
//add debugging code
Enumeration requestAttributeNames = request.getAttributeNames();
while (requestAttributeNames.hasMoreElements()) {
String key = (String) requestAttributeNames.nextElement();
String value = request.getAttribute(key).toString();
System.out.println("request attribute: key = " + key + "; value = " +
value);
}
HttpSession session = request.getSession();
Enumeration sessionAttributeNames = session.getAttributeNames();
while (sessionAttributeNames.hasMoreElements()) {
String key = (String) sessionAttributeNames.nextElement();
String value = session.getAttribute(key).toString();
System.out.println("session attribute: key = " + key + "; value = " +
value);
}
ServletContext app = servlet.getServletContext();
Enumeration appAttributeNames = app.getAttributeNames();
while (appAttributeNames.hasMoreElements()) {
String key = (String) appAttributeNames.nextElement();
String value = app.getAttribute(key).toString();
System.out.println("app attribute: key = " + key + "; value = " + value);
}
return forward;
}
}
Now you can see what's available to your Action (and to your JSP after
the Action handles the request) as far as attributes go.
You can just turn this debugging on and off in struts-config.xml by
telling Struts whether to use the custom request processor in the
"controller" element:
<controller processorClass="MyRequestProcessor"/>
Commenting this out causes the default processor to be used again.
Hope that helps,
Erik
Ben Taylor wrote:
>I must admit I'm a little unsure of how to do that within the JSP.
>I'm tempted to use request.getRequestURI() from within the
>StrutsAction and place that value into the session / request under my
>own variable name.... Obviously if a value already exists that is in
>scope I'd much prefer to use that.
>
>Cheers.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: RequestURI (Action not JSP)
Posted by Ben Taylor <be...@gmail.com>.
I must admit I'm a little unsure of how to do that within the JSP.
I'm tempted to use request.getRequestURI() from within the
StrutsAction and place that value into the session / request under my
own variable name.... Obviously if a value already exists that is in
scope I'd much prefer to use that.
Cheers.
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org
Re: RequestURI (Action not JSP)
Posted by Erik Weber <er...@mindspring.com>.
I don't have the best answer, but I've got two ideas for you.
One is to remember that the ActionMapping (which inherits from
ActionConfig) instance is available to the setup action before you
transfer control to your JSP. Not sure if that would help or not.
Also, I found it very helpful to override a RequestProcessor method
(such as processPath) and print all the request, session and application
scoped attributes out to the console for each request during
development. If I recall, something pretty close to what you want is
available as an attribute in some scope, but I can't exactly remember
the key. Checking the "constant field values" page in the API docs might
help, but I found it easier to just print them all out and see for myself.
Erik
Ben Taylor wrote:
>Can anyone tell me if it is possible to extract the name of the
>current action from within a JSP? ie. /welcome.do, or
>/secure/login.do... Is there a tag that can do this - maybe within
>one of the additional tag libraries?
>
>Thank you in advance.
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
>For additional commands, e-mail: user-help@struts.apache.org
>
>
>
>
---------------------------------------------------------------------
To unsubscribe, e-mail: user-unsubscribe@struts.apache.org
For additional commands, e-mail: user-help@struts.apache.org