struts2如何让获取包含参数的完整的url?
有些页面需要用户登录后才可以访问,为了实现登录成功后跳转回继续访问于是记录下跳转到登录页面前要访问的页面的url,如何取得这个url包含它的?后面带的参数我这里有个方法但...
有些页面需要用户登录后才可以访问,为了实现登录成功后跳转回继续访问 于是记录下跳转到登录页面前要访问的页面的url,如何取得这个url 包含它的 ?后面带的参数
我这里有个方法但是只是取得action的名字具体参数不知道如何取得,求高手帮助。
private void setGoingToURL(Map session, ActionInvocation invocation){
String url = "";
String namespace = invocation.getProxy().getNamespace();
if (StringUtils.isNotBlank(namespace) && !namespace.equals("/")){
url = url + namespace;
}
String actionName = invocation.getProxy().getActionName();
if (StringUtils.isNotBlank(actionName)){
url = url + "/" + actionName + ".action";
}
session.put(GOING_TO_URL_KEY, url);
}
} 展开
我这里有个方法但是只是取得action的名字具体参数不知道如何取得,求高手帮助。
private void setGoingToURL(Map session, ActionInvocation invocation){
String url = "";
String namespace = invocation.getProxy().getNamespace();
if (StringUtils.isNotBlank(namespace) && !namespace.equals("/")){
url = url + namespace;
}
String actionName = invocation.getProxy().getActionName();
if (StringUtils.isNotBlank(actionName)){
url = url + "/" + actionName + ".action";
}
session.put(GOING_TO_URL_KEY, url);
}
} 展开
展开全部
public class Login implements ServletRequestAware{
HttpServletRequest request;
public String login(){
Map map = request.getParameterMap();
Iterator it = map.keySet().iterator();
String paramStr = "";
while(it.hasNext()){
String key = it.next().toString();
String value = request.getParameter(key);
paramStr += key + "=" + value + "&";
}
//完整的请求
System.out.println(request.getRequestURL()+"?"+paramStr);
return null;
}
public void setServletRequest(HttpServletRequest arg0) {
this.request = arg0;
}
}
不知道有什么更好的方式能说明,我写了一个方法,
大体的思路是:实现一个 ServletRequestAware 接口,通过setServletRequest得到request,然后从request得取参数名称集合,遍历集合,从请求中获取value。再将其拼在一起。
哈哈,好像有点笨,但是只能想到这么多了,希望对你有帮助。
HttpServletRequest request;
public String login(){
Map map = request.getParameterMap();
Iterator it = map.keySet().iterator();
String paramStr = "";
while(it.hasNext()){
String key = it.next().toString();
String value = request.getParameter(key);
paramStr += key + "=" + value + "&";
}
//完整的请求
System.out.println(request.getRequestURL()+"?"+paramStr);
return null;
}
public void setServletRequest(HttpServletRequest arg0) {
this.request = arg0;
}
}
不知道有什么更好的方式能说明,我写了一个方法,
大体的思路是:实现一个 ServletRequestAware 接口,通过setServletRequest得到request,然后从request得取参数名称集合,遍历集合,从请求中获取value。再将其拼在一起。
哈哈,好像有点笨,但是只能想到这么多了,希望对你有帮助。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
里面拿这个参数的值。方法二:String param = ServletActionContext.getRequest().getParameter(
追问
你好,请看我的问题补充里面,如何生成完整的url
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
哥们这里应该有你想要的(获得访问者来源和request.getHeader方法的内容):
System.out.println("Protocol: " + request.getProtocol());
System.out.println("Scheme: " + request.getScheme());
System.out.println("Server Name: " + request.getServerName() );
System.out.println("Server Port: " + request.getServerPort());
System.out.println("Protocol: " + request.getProtocol());
System.out.println("Server Info: " + getServletConfig().getServletContext().getServerInfo());
System.out.println("Remote Addr: " + request.getRemoteAddr());
System.out.println("Remote Host: " + request.getRemoteHost());
System.out.println("Character Encoding: " + request.getCharacterEncoding());
System.out.println("Content Length: " + request.getContentLength());
System.out.println("Content Type: "+ request.getContentType());
System.out.println("Auth Type: " + request.getAuthType());
System.out.println("HTTP Method: " + request.getMethod());
System.out.println("Path Info: " + request.getPathInfo());
System.out.println("Path Trans: " + request.getPathTranslated());
System.out.println("Query String: " + request.getQueryString());
System.out.println("Remote User: " + request.getRemoteUser());
System.out.println("Session Id: " + request.getRequestedSessionId());
System.out.println("Request URI: " + request.getRequestURI());
System.out.println("Servlet Path: " + request.getServletPath());
System.out.println("Accept: " + request.getHeader("Accept"));
System.out.println("Host: " + request.getHeader("Host"));
System.out.println("Referer : " + request.getHeader("Referer"));
System.out.println("Accept-Language : " + request.getHeader("Accept-Language"));
System.out.println("Accept-Encoding : " + request.getHeader("Accept-Encoding"));
System.out.println("User-Agent : " + request.getHeader("User-Agent"));
System.out.println("Connection : " + request.getHeader("Connection"));
System.out.println("Cookie : " + request.getHeader("Cookie"));
System.out.println("Created : " + session.getCreationTime());
System.out.println("LastAccessed : " + session.getLastAccessedTime());
System.out.println("Protocol: " + request.getProtocol());
System.out.println("Scheme: " + request.getScheme());
System.out.println("Server Name: " + request.getServerName() );
System.out.println("Server Port: " + request.getServerPort());
System.out.println("Protocol: " + request.getProtocol());
System.out.println("Server Info: " + getServletConfig().getServletContext().getServerInfo());
System.out.println("Remote Addr: " + request.getRemoteAddr());
System.out.println("Remote Host: " + request.getRemoteHost());
System.out.println("Character Encoding: " + request.getCharacterEncoding());
System.out.println("Content Length: " + request.getContentLength());
System.out.println("Content Type: "+ request.getContentType());
System.out.println("Auth Type: " + request.getAuthType());
System.out.println("HTTP Method: " + request.getMethod());
System.out.println("Path Info: " + request.getPathInfo());
System.out.println("Path Trans: " + request.getPathTranslated());
System.out.println("Query String: " + request.getQueryString());
System.out.println("Remote User: " + request.getRemoteUser());
System.out.println("Session Id: " + request.getRequestedSessionId());
System.out.println("Request URI: " + request.getRequestURI());
System.out.println("Servlet Path: " + request.getServletPath());
System.out.println("Accept: " + request.getHeader("Accept"));
System.out.println("Host: " + request.getHeader("Host"));
System.out.println("Referer : " + request.getHeader("Referer"));
System.out.println("Accept-Language : " + request.getHeader("Accept-Language"));
System.out.println("Accept-Encoding : " + request.getHeader("Accept-Encoding"));
System.out.println("User-Agent : " + request.getHeader("User-Agent"));
System.out.println("Connection : " + request.getHeader("Connection"));
System.out.println("Cookie : " + request.getHeader("Cookie"));
System.out.println("Created : " + session.getCreationTime());
System.out.println("LastAccessed : " + session.getLastAccessedTime());
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询