getRequestUri与getRequestUrl获取相关请求参数的区别
程序员文章站
2024-02-18 18:30:28
...
test1.jsp
<a href ="test.jsp?p=pink">跳转到test2</a>
test2.jsp
<%@ page language="java" import="java.util.*" pageEncoding="gb2312"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
system.out.println("basePath:"+basePath);
system.out.println("<br/>");
system.out.println("getContextPath:"+request.getContextPath());
system.out.println("<br/>");
system.out.println("getServletPath:"+request.getServletPath());
system.out.println("<br/>");
system.out.println("getRequestURI:"+request.getRequestURI());
system.out.println("<br/>");
system.out.println("getRequestURL:"+request.getRequestURL());
system.out.println("<br/>");
system.out.println("getRealPath:"+request.getRealPath("/"));
system.out.println("<br/>");
system.out.println("getServletContext().getRealPath:"+getServletContext().getRealPath("/"));
system.out.println("<br/>");
system.out.println("getQueryString:"+request.getQueryString());
%>
显示结果:
basePath:http://localhost:8080/test/
getContextPath:/test
getServletPath:/test.jsp
getRequestURI:/test/test.jsp
getRequestURL:http://localhost:8080/test/test.jsp
getRealPath:D:\Tomcat 6.0\webapps\test\
getServletContext().getRealPath:D:\Tomcat 6.0\webapps\test\
getQueryString:p=pink
上一篇: Android实战开发:获得屏幕物理尺寸、密度及分辨率
下一篇: Map组装成url请求参数