您的位置:首页 > 产品设计 > UI/UE

如何区分:Request中getContextPath、getServletPath、getRequestURI、request.getRealPath

2016-04-24 14:54 429 查看
假定你的web application 名称为Web_day19

你在浏览器中输入请求路径:http://localhost:8184/Web_day19/userServlet?method=getUser

System.out.println("request.getContextPath() : "+request.getContextPath() );

打印结果:request.getContextPath() : /Web_day19

System.out.println("request.getServletPath() : " + request.getServletPath());

打印结果:request.get[b]ServletPath()
: /userServlet[/b]



System.out.println(" request.getRequestURI() : " + request.getRequestURI() );

打印结果:request.getRequestURI()
: /Web_day19/userServlet



System.out.println("request.getRealPath("/") : "+ request.getRealPath("/") );

打印结果:

request.getRealPath("/") : D:\javastudy\javaWeb\.metadata\.plugins\org.eclipse.wst.server.core\tmp0\wtpwebapps\Web_day19\
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: