欢迎您访问程序员文章站本站旨在为大家提供分享程序员计算机编程知识!
您现在的位置是: 首页

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

相关标签: 获取请求参数