|
||||||||||||
|
|
| 在Servlet与JSP中取得当前文件所在的相对路径与绝对路径 |
| 时间:22/04/2007 作者:网络 来源:网络 |
| 小提示→点这里把文章加入您的收藏夹,方便下次查看 |
| 设置文章字体大小:[大 中 小] |
|
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.io.*" %>
<%
//在Servlet与JSP中取得当前文件所在的相对路径与绝对路径
//JSP中
out.println("根目录所对应的绝对路径:" + request.getRequestURI() + " "); String strPathFile = application.getRealPath(request.getRequestURI()); out.println("文件的绝对路径:" + strPathFile+ " "); out.println(application.getRealPath(request.getRequestURI())); String strDirPath = new File(application.getRealPath(request.getRequestURI())).getParent(); out.println("目录的绝对路径:" + strDirPath + " "); %> //Servlet中 //JSP中的application对象就是Servlet中的ServerContext,所以在Servlet中是如此获得 //import java.io.File; System.out.println("根目录所对应的绝对路径:" + request.getServletPath() + " "); String strPathFile = request.getSession().getServletContext().getRealPath(request.getRequestURI()); System.out.println("文件的绝对路径:" + strPathFile + " "); String strDirPath = new File(request.getSession().getServletContext().getRealPath(request.getRequestURI())).getParent(); System.out.println("目录的绝对路径:" + strDirPath + " "); 文件名不能包括以下字符:\/:*?"<>| |
|
上一篇:wonderful learning website for java development
下一篇:Tomcat 5.5.x 配置集锦(x表示4,5,.6,7) |
| 【返回】 【顶部】 【关闭】 |
| Copyright © 2005-2010 www.594k.com All Rights Reserved. |
| 版权所有:JAVA学习网
备案序号:皖ICP备06004238号 |