java如何使用session或cookie记录当前浏览网页的地址,并能在登陆后直接返回到该页面?
java如何使用session或cookie记录当前浏览网页的地址,并能在登陆后直接返回到该页面?
------解决方案--------------------/**
* 获取完整的URL
* @param request
* @return
*/
public static String getRequestURL(HttpServletRequest request) {
if (request == null) {
return "";
}
String url = "";
url = request.getContextPath();
url = url + request.getServletPath();
java.util.Enumeration names = request.getParameterNames();
int i = 0;
// String requestPageUrl = "";
if (names != null) {
while (names.hasMoreElements()) {
String name = (String) names.nextElement();
if (name.equals("requestPageUrl")
------解决方案-------------------- name.indexOf("log") != -1) {
// requestPageUrl = request.getParameter(name);
continue;
}
if (i == 0) {
url = url + "?";
}
else {
url = url + "&";
}
i++;
String value = request.getParameter(name);
if (value == null) {
value = "";
}
url = url + name + "=" + value;
}
}
try {
java.net.URLEncoder.encode(url, "ISO-8859");
}
catch (Exception e) {
}
return url;
}
在前台jsp里面隐含一个<input type="hidden" name="requestUrl" >
在提交的后台action 或则 servlet中,调用我刚写的这个方法,就可以把当前的url放到 requestUrl里了啊,登陆后在跳到这个url就可以了