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-博客
查看全文
  • 相关阅读:
    yafu安装使用方法以及mismatched parens解决方法
    Bubble Babble Binary Data Encoding的简介以及bubblepy的安装使用方法
    python-gzip解压缩(实验吧SOS)
    python用模块zlib压缩与解压字符串和文件的方法
    IDA-IDC脚本编写语法
    南邮CTF密码学,mixed_base64
    各种类型文件头标准编码
    实验吧,心中无码
    Vue + webpack的纯前端项目如何配置外部配置文件
    js小技巧
  • 原文地址:https://www.cnblogs.com/owenyang/p/3579122.html
  • Copyright © 2011-2022 走看看