摘:jsp中獲取當前路徑

fog911811發表於2010-07-08
  1. <%@ page contentType="text/html; charset=gb2312" language="java" import="java.io.*" errorPage="" %>  
  2. <html>  
  3. <head>  
  4. <meta http-equiv="Content-Type" content="text/html; charset=gb2312">  
  5. <title>Untitled Document</title>  
  6. </head>  
  7.   
  8. <body>  
  9. 當前WEB應用的物理路徑:<%=application.getRealPath("/")%><BR>  
  10. 當前你求請的JSP檔案的物理路徑:<%=application.getRealPath(request.getRequestURI())%><BR>  
  11. <%   
  12. String path=application.getRealPath(request.getRequestURI());   
  13. String dir=new File(path).getParent();   
  14. out.println("當前JSP檔案所在目錄的物理路徑"+dir+"</br>");   
  15. String realPath1 = "http://" + request.getServerName() + ":" + request.getServerPort() + request.getContextPath()+request.getServletPath().substring(0,request.getServletPath().lastIndexOf("/")+1);    
  16. out.println("web URL 路徑:"+realPath1);   
  17. %>  
  18. </body>  
  19. </html>   

相關文章