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-博客
查看全文
  • 相关阅读:
    使用Python连接redis(redis作MQ使用)_Tister的空间_百度空间
    LTTng 2.0 Downloads | LTTng Project
    How to capture stdout in realtime with Python « SaltyCrane Blog
    python的线程锁机制_dominic_80ChinaUnix博客
    Collective Intelligence实战/阿拉克(Satnam Alag)图书卓越亚马逊 [集体智慧编程]
    查IP
    沃尔玛控股中国1号店
    HeidiSQL MySQL made easy
    groovy学习7groovy sql 雪霁霜飞 博客园
    数据集 (DataSet) groovy
  • 原文地址:https://www.cnblogs.com/owenyang/p/3579122.html
  • Copyright © 2011-2022 走看看