In struts 2 there is a struts tag where you can specify the name of the action, and it gives a URL to this action:
<s:url action="action_name" />
I searched for a while to find out if this is possible in the Struts2 Action / Interceptor. I found a class that refers to this struts tag, I think ( org.apache.struts2.components.URL ), but cannot figure out how to use it.
This is, as I understand it, but it may not be how to use it (if at all possible), but any method that I call after that just gives me NullPointerExceptions .:
public String intercept(ActionInvocation ai) throws Exception { HttpServletRequest request = ServletActionContext.getRequest(); HttpServletResponse response = ServletActionContext.getResponse(); URL url = new URL(ai.getStack(), request, response); url.setAction("login");
Hoping this can be done, as it would save a lot of pipe!
Thanks.
EDIT
URL url = new URL(invocation.getStack(), request, response); url.setActionMapper(new DefaultActionMapper()); String redirectUrl = url.getUrlProvider().determineActionURL("action_name", invocation.getProxy().getNamespace(), invocation.getProxy().getMethod(), request, response, request.getParameterMap(), "http", true, true, false, false);
This code really works and gives me the redirect URL, but I was wondering if there is a way to get the CURRENT ActionMapper instead of creating a new one. I did a quick google but can't find anything.