关于servlet中的路径的几个函数的例子:
假设有如下请求的路径:
1. /CitizenWeb
request.getContextPath();
2. TestServlet
request.getRequestURI().substring(request.getRequestURI().lastIndexOf("/") + 1);
3. /CitizenWeb/TestServlet
request.getRequestURI();
5. dd=00030&ywdm=01&czmd=02
getUrl(request)
private String getUrl(HttpServletRequest request)
{
String url = "";
Enumeration param = request.getParameterNames();
while (param.hasMoreElements()) {
String pname = param.nextElement().toString();
if (!pname.equalsIgnoreCase("pagenum") && !pname.equalsIgnoreCase("submit"))
url += pname + "=" + request.getParameter(pname) + "&";
}
if (url.endsWith("&")) {
url = url.substring(0, url.lastIndexOf("&"));
}
return url;
}
request.getRequestURL()+"?"+getUrl(request);