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

你可能感兴趣的:(servlet中获得tomcat项目根目录的绝对路径)