2007-02-02

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

关键字: 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 {
  String  filePath = config.getServletContext().getRealPath("/");
 }

}


或者直接在继承了HttpServlet的Servlet中写:

String  filePath=this.getServletConfig().getServletContext().getRealPath("/");
评论
发表评论

您还没有登录,请登录后发表评论