zoukankan      html  css  js  c++  java
  • JSP各种路径的获取


    <%@ page contentType="text/html; charset=utf8" 
     	language="java" import="java.io.*" errorPage="" %>
     <html>
     <head>
     <meta http-equiv="Content-Type" content="text/html; charset=utf8">
     <title>Get Paths</title>
     </head>
     
     <body>
     当前WEB应用的物理路径:<%=application.getRealPath("/")%><BR><hr>
     当前你求请的JSP文件的物理路径:<%=application.getRealPath(request.getRequestURI())%><BR><hr>
     <%
     String path=application.getRealPath(request.getRequestURI());
     String dir=new File(path).getParent();
     out.println("当前JSP文件所在目录的物理路径"+dir+"<br><hr><p>");
     
     String realPath1 = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()+request.getServletPath().substring(0,request.getServletPath().lastIndexOf("/")+1); 
     out.println("web URL 路径:"+realPath1+"<br><hr>");
     
     String realPath2 = request.getContextPath();
     out.println("getContextPath: "+realPath2+"<br><hr>");
     
     String realPath3 = request.getServletPath().substring(0,request.getServletPath().lastIndexOf("/")+1); 
     out.println("getServletPath: "+realPath3);
     %>
     </body>
     </html> 

    执行结果:


    当前WEB应用的物理路径:F:\115Synchronization\code save\JSP\


    当前你求请的JSP文件的物理路径:F:\115Synchronization\code save\JSP\web\web\src\fundation\getPath.jsp

    当前JSP文件所在目录的物理路径F:\115Synchronization\code save\JSP\web\web\src\fundation

    web URL 路径:http://localhost:8080/web/web/src/fundation/


    getContextPath: /web

    getServletPath: /web/src/fundation/ 

  • 文章声明
  • 作者:Owen
  • 出处: http://www.cnblogs.com/owenyang
  • 本文版权归作者,欢迎转载,但未经作者同意必须保留此段声明,且在文章页面明显位置给出原文连接,否则保留追究法律责任的权利。该博客同步发在 HEXO-博客
查看全文
  • 相关阅读:
    藏!Java编程技巧之单元测试用例编写流程 原创 常意 阿里技术 2021-05-12
    时间,遵循rfc3339标准格式 unix时间戳
    微软面试题: LeetCode 240. 搜索二维矩阵 II 出现次数:3
    微软面试题: LeetCode 69. x 的平方根 出现次数:3
    微软面试题: LeetCode 138. 复制带随机指针的链表 出现次数:3
    微软面试题: LeetCode 384. 打乱数组 出现次数:3
    微软面试题: LeetCode 207. 课程表 出现次数:3
    微软面试题: LeetCode 98. 验证二叉搜索树 出现次数:3
    CF1537E2 Erase and Extend (Hard Version) 题解
    洛谷 P4332 [SHOI2014]三叉神经树 题解
  • 原文地址:https://www.cnblogs.com/owenyang/p/3579122.html
  • Copyright © 2011-2022 走看看