空间站

北极心空

  BlogJava :: 首页 :: 联系 :: 聚合  :: 管理
  15 Posts :: 393 Stories :: 160 Comments :: 0 Trackbacks

在Servlet与JSP中取得当前文件所在的相对路径与绝对路径

//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 + "
");

文件名不能包括以下字符:\/:*?"<>|

posted on 2006-11-02 10:35 芦苇 阅读(1072) 评论(0)  编辑  收藏

只有注册用户登录后才能发表评论。


网站导航: