`

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

阅读更多

假定你的WebApplication 名称为swcrm,你在浏览器中输入请求路径:

http://localhost:8080/swcrm/admin/show.jsp
则执行下面向行代码后打印出如下结果:

1、 System.out.println(request.getContextPath());
打印结果:/swcrm
  2、System.out.println(request.getServletPath());
打印结果:/admin/show.jsp

3、 System.out.println(request.getRequestURI());
打印结果:/swcrm/admin/show.jsp

4、 System.out.println(request.getRealPath("/"));
打印结果:F:\Tomcat 6.0\webapps\swcrm\

 

J2EE api中文版  http://doc.java.sun.com/DocWeb/

0
0
分享到:
评论

相关推荐

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

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

    request.getcontextPath()_详解

    request.getcontextPath()详解

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

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

    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 { //...

    WEB15-request.rar

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

    request的使用.txt

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

    很经典的登录回选。

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

    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

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

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

    新闻推荐系统

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

    ext时间控件,可以选择时分秒

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

    JSP EIMS系统-OA子系统的设计与开发(源代码+lw).zip

    <link href="<%=request.getContextPath()+user.getSkinPath()%>/css/style_new.css" rel="stylesheet" type="text/css"> <script language="JavaScript" src="../../../script/Popcalendar.js"> String...

    Android代码-YuanNews

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

    用户管理系统(ums)

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

    登录过滤器

    response.sendRedirect(request.getContextPath()); }else{ chain.doFilter(request, response); } } web.xml配置: <filter-name>accessFilter <filter-class>com.loginFilter</filter-class> ...

    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...

    servlet电子书籍 pdf格式

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

Global site tag (gtag.js) - Google Analytics