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中写:

Java代码 String  filePath=this.getServletConfig().getServletContext().getRealPath(“/”); 

版权声明:本文为tianguook原创文章,遵循 CC 4.0 BY-SA 版权协议,转载请附上原文出处链接和本声明。
本文链接:https://www.cnblogs.com/tianguook/p/3187276.html