急!! 在一个Servlet中怎么获得一个文件的绝对路径 如题 解决方案 » 免费领取超大流量手机卡,每月29元包185G流量+100分钟通话, 中国电信官方发货 在Servlet与JSP中取得当前文件所在的相对路径与绝对路径-----------------------------------------------------------------------------------------http://iamin.blogdriver.com/iamin/504479.html <%@ page contentType="text/html;charset=GBK"%> <%@ page import="java.io.*" %> <% //在Servlet与JSP中取得当前文件所在的相对路径与绝对路径 //JSP中 out.println("根目录所对应的绝对路径:" + request.getRequestURI() + "<br/>"); String strPathFile = application.getRealPath(request.getRequestURI()); out.println("文件的绝对路径:" + strPathFile+ "<br/>"); out.println(application.getRealPath(request.getRequestURI())); String strDirPath = new File(application.getRealPath(request.getRequestURI())).getParent(); out.println("目录的绝对路径:" + strDirPath + "<br/>"); %> //Servlet中 //JSP中的application对象就是Servlet中的ServerContext,所以在Servlet中是如此获得 //import java.io.File; System.out.println("根目录所对应的绝对路径:" + request.getServletPath() + "<br/>"); String strPathFile = request.getSession().getServletContext().getRealPath(request.getRequestURI()); System.out.println("文件的绝对路径:" + strPathFile + "<br/>"); String strDirPath = new File(request.getSession().getServletContext().getRealPath(request.getRequestURI())).getParent(); System.out.println("目录的绝对路径:" + strDirPath + "<br/>"); //获取Web项目的全路径 String strFullPath = getServletContext().getRealPath("/"); out.println(strFullPath); //获得Web项目的上下文路径 String strContextPath = request.getContextPath(); out.println(strContextPath); JQuery自动补全,中文问题 checkbox 值的传递问题 struts2 一个action 转发到 另一个 action 在类内部转发 刚接触编程 求jsp分页代码, 列子 b/s结构系统如何读取com口数据? 请大家帮我看看这是什么问题呢? 在线等待...请问在JAVA中怎样将XML文件中数据更新到数据库表中?急!!! 如何从数据库中读取图片(UP给分!) 招聘北京JSP程序员,待遇优厚,有兴趣联系 如何把long型转为String型?.. 欧几里得算法---求助--满分相送 sns算法
-----------------------------------------------------------------------------------------http://iamin.blogdriver.com/iamin/504479.html
<%@ page contentType="text/html;charset=GBK"%>
<%@ page import="java.io.*" %>
<%
//在Servlet与JSP中取得当前文件所在的相对路径与绝对路径
//JSP中
out.println("根目录所对应的绝对路径:" + request.getRequestURI() + "<br/>");
String strPathFile = application.getRealPath(request.getRequestURI());
out.println("文件的绝对路径:" + strPathFile+ "<br/>");
out.println(application.getRealPath(request.getRequestURI()));
String strDirPath = new File(application.getRealPath(request.getRequestURI())).getParent();
out.println("目录的绝对路径:" + strDirPath + "<br/>");
%>
//Servlet中
//JSP中的application对象就是Servlet中的ServerContext,所以在Servlet中是如此获得
//import java.io.File;
System.out.println("根目录所对应的绝对路径:" + request.getServletPath() + "<br/>");
String strPathFile = request.getSession().getServletContext().getRealPath(request.getRequestURI());
System.out.println("文件的绝对路径:" + strPathFile + "<br/>");
String strDirPath = new File(request.getSession().getServletContext().getRealPath(request.getRequestURI())).getParent();
System.out.println("目录的绝对路径:" + strDirPath + "<br/>");
//获取Web项目的全路径
String strFullPath = getServletContext().getRealPath("/");
out.println(strFullPath);
//获得Web项目的上下文路径
String strContextPath = request.getContextPath();
out.println(strContextPath);