aini 发表于 2015-8-10 09:46:08

servlet中获得tomcat项目根目录的绝对路径

  



public class CreateXmlAction extends HttpServlet {
private ServletConfig config;
public void init(ServletConfig config) throws ServletException {
this.config = config;
}
public void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
StringfilePath = config.getServletContext().getRealPath("/");
}
}
  
  或者直接在继承了HttpServlet的Servlet中写:
  Java代码 StringfilePath=this.getServletConfig().getServletContext().getRealPath("/");
页: [1]
查看完整版本: servlet中获得tomcat项目根目录的绝对路径