HttpServletRequest request 相关方法 得到路径
来源:互联网 发布:vivo 微信无法连接网络 编辑:程序博客网 时间:2024/05/22 03:22
//--------------------------POST---------------
username=qqqq
password=wwww
email=1063128263@qq.com
http://192.168.1.211:8080/demo/index.jsp
------------------------------------------------>
request.getContextPath() =/demo
request.getMethod() =POST
request.getRequestURI() =/demo/reg
request.getRequestURL() =http://192.168.1.211:8080/demo/reg
request.getServletPath() =/reg
//-----------------------GET------------------->
http://192.168.1.211:8080/demo/index.jsp?username=1&password=1&email=1
request.getContextPath() =/demo
request.getMethod() =GET
request.getQueryString() =username=1&password=1&email=1
request.getRequestURI() =/demo/index.jsp
request.getRequestURL() =http://192.168.1.211:8080/demo/index.jsp
request.getServletPath() =/index.jsp
< %=request.getContextPath()%>是为了解决相对路径的问题,可返回站点的根路径。(即返回项目名,如果项目路径为根目录则得到"")
但不用也可以吧,比如<a href="<%=request.getContextPath()%>/catalog.jsp">
我就直接用<a href="catalog.jsp">也行啊,这两个文件是在同一个目录下的
比如你要生成一个文件放在服务器上得一个目录下,你可以使用request.getContextPath()+/dir,组成一个完整得目录结构!
但在JSP文件里,通过request.getContextPath()得到的路径却为空,为什么?
你在context中没有配置path属性,所以你的工程文件就是在根目录下,相当于path="";即是你直接在 浏览器中输入你的服务器ip就会到你的jsp页面,而不是tomcat的默认页面;所以你通过request.getContextPath()得到的字 符串是为空的;它是获得虚目录的;
如果你想得到工程文件的实际物理路径,可通过:<%=request.getRealPath("/")%>,这样页面就会输出:d:/web
request.getScheme();
返回的协议名称,默认是http
request.getServerName()
返回的是你浏览器中显示的主机名,你自己试一下就知道了
getServerPort()
获取服务器端口号
getServletPath()
request.getRequestURI()=request.getContextPath()+getServletPath();
request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+request.getContextPath();
- HttpServletRequest request 相关方法 得到路径
- HttpServletRequest获取请求路径相关方法
- HttpServletRequest request 获取当前路径
- request组合得到web路径
- springmvc中获得HttpServletRequest request方法
- springmvc中获得HttpServletRequest request方法 .
- request(HttpServletRequest)对象 【get方法】
- JAVA中得到类相关路径 或 Servlet/JSP相关路径的方法
- HttpServletRequest、request常用方法、request常见应用、请求转发、RequestDispatcher
- HttpServletRequest、request常用方法、request常见应用、请求转发、RequestDispatcher
- HttpServletRequest、request常用方法、request常见应用、请求转发、RequestDispatcher
- ###request获取请求路径内容的相关方法总结。例如:request.getContextPath()。。。
- HttpServletRequest常用获取URL相关的方法
- HttpServletRequest获取URL的相关方法
- request的相关方法
- 如何理解HttpServletRequest request
- HttpServletRequest、 ServletRequest、Request
- httpservletRequest 与Map request
- ajax+jQuery+json
- ubuntu中用命令行把文件移到回收站 move files to trash from command line
- C/C++ 通用 Makefile
- 当rman连接不上 ... sqlnet.ora
- C# Heap(ing) Vs Stack(ing) in .NET: Part I
- HttpServletRequest request 相关方法 得到路径
- 鼠标事件发生时元素的定位
- 怎样花两年时间去面试一个人
- IPA文件格式 MIME
- 正则表达式 清除<>标签样式
- Java数字格式化
- 移位不过是技巧
- eclipse 快捷键
- ibatis如何支持clob 和blob