jsp常见获取地址函数之间的不同

2021-06-30 06:05

阅读:565

标签:pat   pre   port   out   path   request   ext   url   blog   

对jsp中常用地址获取函数进行区分测试函数:

test1.jsp=======================

"test.jsp?p=fuck">跳转到test2

test2.jsp=======================

"java" import="java.util.*" pageEncoding="gb2312"%>

String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";

out.println("basePath:"+basePath);
out.println("
"); out.println("getContextPath:"+request.getContextPath()); out.println("
"); out.println("getServletPath:"+request.getServletPath()); out.println("
"); out.println("getRequestURI:"+request.getRequestURI()); out.println("
"); out.println("getRequestURL:"+request.getRequestURL()); out.println("
"); out.println("getRealPath:"+request.getRealPath("/")); out.println("
"); out.println("getServletContext().getRealPath:"+getServletContext().getRealPath("/")); out.println("
"); 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=fuck

 

jsp常见获取地址函数之间的不同

标签:pat   pre   port   out   path   request   ext   url   blog   

原文地址:http://www.cnblogs.com/2017Crown/p/7137278.html


评论


亲,登录后才可以留言!