java中通过request获取路径中的不同信息

来源:互联网 发布:淘宝返利订单权重 编辑:程序博客网 时间:2024/06/16 09:01

aa为工程中的项目名

bb为webRoot下的文件夹

1、request.getContextPath(); 输出结果:/aa

2、request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path; 输出结果:http://localhost:8080/aa

3、request.getServletPath();(获取客户端请求文件的路径)输出结果:/bb/content/contentList.jsp

4、request.getRequestURI();(获取发出请求字符串的客户端地址,得到的是requestURL的部分值,并且web容器没有decode过的)输出结果:/aa/bb/content/contentList.jsp

5、request.getRequestURL();(返回请求全部,包括http协议,servlet名字,端口号,映射路径,但不包含请求参数,)输出结果:http://localhost:8080/aa/bb/content/contentList.jsp


1 0
原创粉丝点击