熱點推薦:
您现在的位置: 電腦知識網 >> 編程 >> Java編程 >> Java核心技術 >> 正文

jsp如何獲取當前路徑

2022-06-13   來源: Java核心技術 

<%@ page contentType=&#;text/html; charset=gb&#; language=&#;java&#; import=&#;javaio*&#; errorPage=&#; %>

<html>

<head>

<meta httpequiv=&#;ContentType&#; content=&#;text/html; charset=gb&#;>

<title>Untitled Document</title>

</head>

<body>

當前WEB應用的物理路徑<%=applicationgetRealPath(&#;/&#;)%><BR>

當前你求請的JSP文件的物理路徑<%=applicationgetRealPath(requestgetRequestURI())%><BR>

<%

String path=applicationgetRealPath(requestgetRequestURI());

String dir=new File(path)getParent();

outprintln(&#;當前JSP文件所在目錄的物理路徑&#;+dir+&#;</br>&#;);

String realPath = &#;http://&#; + requestgetServerName() + &#;:&#; + requestgetServerPort() + requestgetContextPath()+requestgetServletPath()substring(requestgetServletPath()lastIndexOf(&#;/&#;)+);

outprintln(&#;web URL 路徑:&#;+realPath);

%>

</body>

</html>


From:http://tw.wingwit.com/Article/program/Java/hx/201405/30811.html
    推薦文章
    Copyright © 2005-2022 電腦知識網 Computer Knowledge   All rights reserved.