jsp得到当前页面路径

<%
// 解析属性
String scheme = request.getScheme();
String serverName = request.getServerName();
int serverPort = request.getServerPort();
String requestURI = request.getRequestURI();
String contextPath = request.getContextPath();
String servletPath = request.getServletPath();
String queryString = request.getQueryString();

out.println("scheme = " + scheme + "<br />");
out.println("serverName = " + serverName + "<br />");
out.println("serverPort = " + serverPort + "<br />");
out.println("requestURI = " + requestURI + "<br />");
out.println("contextPath = " + contextPath + "<br />");
out.println("servletPath = " + servletPath + "<br />");
out.println("queryString = " + queryString + "<br />");

// 处理所有参数
java.util.Enumeration e = request.getParameterNames();

while(e.hasMoreElements()){
String paramName = (String)e.nextElement();
String paramValue = (String)request.getParameter(paramName);
out.println(paramName + " = " + paramValue + "<br />");
}
%>

自己优化了一个方法

<%
// 处理所有参数
java.util.Enumeration e = request.getParameterNames();
String paramList = "";
while (e.hasMoreElements()) {
   String paramName = (String) e.nextElement();
   if (!paramName.equals("id")) {
    String[] paramValues = request
    .getParameterValues(paramName);
    if (paramValues != null) {
   for (int i = 0; i < paramValues.length; i++) {
    paramList = paramList + paramName + "="
    + paramValues[i] + "&";
   }
    }
   }
}
%>

你可能感兴趣的:(java,jsp,Scheme)