`

Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别

阅读更多
假定你的web application 名称为news,你在浏览器中输入请求路径:

http://localhost:8080/news/main/list.jsp

则执行下面向行代码后打印出如下结果:

1、 System.out.println(request.getContextPath());
打印结果:/news

  2、System.out.println(request.getServletPath());
打印结果:/main/list.jsp

3、 System.out.println(request.getRequestURI());
打印结果:/news/main/list.jsp

4、 System.out.println(request.getRealPath("/"));
打印结果:F:\Tomcat 6.0\webapps\news\test
分享到:
评论

相关推荐

    Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别.doc

    Request中getContextPath、getServletPath、getRequestURI、request.getRealPath的区别

    java中request.getcontextPath()的意思.doc

    java中request.getcontextPath()的意思.doc

    request.getcontextPath()_详解

    request.getcontextPath()详解

    Request中getContextPath、getServletPath的区别

    NULL 博文链接:https://javachikuang.iteye.com/blog/262264

    数据库测试test.sql

    response.sendRedirect(request.getContextPath()+"/admin/login.jsp"); } public void register(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { //...

    很经典的登录回选。

    if (session.getAttribute("person") == null) ... response.sendRedirect(request.getContextPath() + "/login.jsp"); }else{ request.getRequestDispatcher("fall.jsp").forward(request, response); }

    request的使用.txt

    String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> ``` 该语句用于获取当前网页的相对路径 例如: 访问...

    servlet电子书籍 pdf格式

    servlet课件Servlet课件.........................................................request.getContextPath()方法 ................................................8 等等。。。。。。。。。。。。。。。。。。。。

    新闻推荐系统

    所有的jsp页面中的链接 添加 request.getContextPath() , 确保路径正确使用!! 代码中使用到了重定向等页面跳转,添加 request.getContextPath() , 确保路径正确使用!! dao 层中的接口不要随意修改,如果需要...

    Android代码-YuanNews

    所有的jsp页面中的链接 添加 request.getContextPath() , 确保路径正确使用!! 代码中使用到了重定向等页面跳转,添加 request.getContextPath() , 确保路径正确使用!! dao 层中的接口不要随意修改,如果需要...

    WEB15-request.rar

    String getRequestURI() StringBuffer getRequestURL() String getContextPath() ---web应用的名称 String getQueryString() ---- get提交url地址后的参数字符串 username=zhangsan&password=123 注意:request...

    servlet2.4doc

    The doFilter method of the Filter is called by the container each time a request/response pair is passed through the chain due to a client request for a resource at the end of the chain. doGet...

    SpringMVC批量上传

    String path = request.getServletContext().getRealPath("/images/")+mkdir; //System.out.println("path="+path); File filepath = new File(path,filename); if(!filepath.getParentFile(&#...

    网页视频播放插件

    最近做的一个项目,网页中需要播放视频。 这里包括 我自己做的java工程的jsp里的 demo 和 js插件包..。 不用下载其他播放插件,轻巧简捷 只需两步: 1.把代码全部复制,更改一下视频路径 2.把js包放入项目里。然后...

    JSP实现简单的用户登录并显示出用户信息的方法

    本文实例讲述了JSP实现简单的用户登录并...String path = request.getContextPath();  String basePath = request.getScheme()+”://”+request.getServerName()+”:”+request.getServerPort()+path+”/”;  %> 

    最简单js代码实现select二级联动下拉菜单

    String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %> <!DOCTYPE HTML PUBLIC "-//W3C//DTD H

    用户管理系统(ums)

    用户管理系统。语言JAVA public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, ... response.sendRedirect(request.getContextPath()+"/manager.jsp"); }

    DWR开发包常规客户端服务器端面向对象编程

    dwr开发包,常规客户端...<script type='text/javascript' src='<%=request.getContextPath()%>/dwr/interface/TestService.js'> <script type='text/javascript' src='<%=request.getContextPath()%>/dwr/engine.js'> ...

    JSP的request对象实例详解

    客户端的请求信息被封装在request对象中,通过它才能了解客户的需求,然后做出响应。它是HttpServletRequest类的实例。request对象具有请求域,即完成客户端的请求之前,该对象一直有效。  二 request对象方法  ...

    Java后端实现websocket与微信小程序端连接简单例子

    String path = request.getContextPath(); String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/"; %>   <!DOCTYPE HTML> <html>  <head> ...

Global site tag (gtag.js) - Google Analytics