Request 获取路径

来源:互联网 发布:烽火通信与华讯网络 编辑:程序博客网 时间:2024/06/06 17:33

转载自:http://blog.163.com/jackswu@yeah/blog/static/14062912320110111000234/

如果请求的URL为:http://localhost:8080/webapp/login

那么分别调用request.getContextPath( )request.getServletPath( ) request.getURI( )request.getURL( )分别返回什么路径?


这几个方法都是在HttpServletRequest接口中定义的。


1.request.getURI( )或者request.getRequestURI()返回HTTP请求行中请求URI的部分。上例中该方法将返回/webapp/login。

2.request.getContextPath( )返回web应用程序的路径,上例中该方法将返回/webapp。

3.request.getServletPath( ) 返回Servlet的路径。上例中该方法将返回/login。

4.request.getURL( )或者request.getRequestURL()返回请求的URL,上例中即为http://localhost:8080/webapp/login。
原创粉丝点击