If I typed url as localhost:8080/MyApp/loginAction.action?username=raj&password=123
how will I get url as it is in interceptor/action class? I tried some methods of request object but not getting. used request.getRequestURL()
,request.getQueryString()
....etc
Asked
Active
Viewed 3,737 times
1

Andrea Ligios
- 49,480
- 26
- 114
- 243

jagannath
- 93
- 2
- 11
-
You can use `param` tag which always adds parameters to the url, unfortunately you can't use it with the `form` tag. – Roman C Sep 14 '15 at 15:33
1 Answers
3
You can use HttpServletRequest.getRequestURL()
to get the full URL excluding the parameters (the "?foo=bar"
part, that is called QueryString).
You can get the QueryString, if any (and without the ?
sign), with HttpServletRequest.getQueryString()
.
In an INTERCEPTOR, getting the request from the ActionContext:
public String intercept(ActionInvocation invocation) throws Exception {
final ActionContext context = invocation.getInvocationContext();
HttpServletRequest request = (HttpServletRequest)context.get(StrutsStatics.HTTP_REQUEST);
String url = request.getRequestURL();
String queryString = request.getQueryString();
String fullUrl = url + (queryString==null ? "" : ("?" + queryString));
LOG.debug(fullUrl);
return invocation.invoke();
}
In an ACTION, getting the request from ServletRequestAware:
public class MyAction implements ServletRequestAware {
private javax.servlet.http.HttpServletRequest request;
public void setServletRequest(javax.servlet.http.HttpServletRequest request){
this.request = request;
}
public String execute(){
String url = request.getRequestURL();
String queryString = request.getQueryString();
String fullUrl = url + (queryString==null ? "" : ("?" + queryString));
LOG.debug(fullUrl);
return Action.SUCCESS;
}
}

Community
- 1
- 1

Andrea Ligios
- 49,480
- 26
- 114
- 243