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-博客
查看全文
  • 相关阅读:
    Codeforces Round #548
    省选前的th题
    省选前多项式的挣扎
    2019.3.18考试&2019.3.19考试&2019.3.21考试
    省选前的反演抢救计划
    2019.3.16 noiac的原题模拟赛
    AtCoder Regular Contest 069 F
    Atcoder Grand 012 C
    Atcoder Grand 011 C
    Atcoder Grand 006 C-Rabbit Exercise
  • 原文地址:https://www.cnblogs.com/owenyang/p/3579122.html
  • Copyright © 2011-2022 走看看