JSP页面
<% String url = request.getScheme()+"://"+ request.getServerName()+request.getRequestURI()+"?"+request.getQueryString(); %>
JAVA代码
String basePath = request.getScheme()+"://"+request.getServerName();
String gotoURL = request.getRequestURI();
gotoURL = gotoURL.replaceAll("//", "/");
if(gotoURL.indexOf("/WEB-INF/jsp/") != -1){
gotoURL = gotoURL.replace("/WEB-INF/jsp/","/");
gotoURL = gotoURL.replace(".jsp",".shtm");
}
gotoURL = basePath+gotoURL;
String queryStr = request.getQueryString();
if(queryStr!=null){
gotoURL = gotoURL +"?"+queryStr;
}
try {
gotoURL = URLEncoder.encode(gotoURL,"UTF-8");
} catch (Exception e1) {
e1.printStackTrace();
String gotoURL = request.getRequestURI();
gotoURL = gotoURL.replaceAll("//", "/");
if(gotoURL.indexOf("/WEB-INF/jsp/") != -1){
gotoURL = gotoURL.replace("/WEB-INF/jsp/","/");
gotoURL = gotoURL.replace(".jsp",".shtm");
}
gotoURL = basePath+gotoURL;
String queryStr = request.getQueryString();
if(queryStr!=null){
gotoURL = gotoURL +"?"+queryStr;
}
try {
gotoURL = URLEncoder.encode(gotoURL,"UTF-8");
} catch (Exception e1) {
e1.printStackTrace();
}