无法在httpServlet的init方法中创建目录

时间:2015-09-13 01:08:55

标签: java servlets

在下面的代码中,每当我启动服务器或整个应用程序时,都会调用init方法。如果它们不存在,那么应该创建目标。但在我的系统中它没有被创建。当我用main方法编写一个简单的java类时,它的创建成功(目录创建代码在main方法本身)。有关信息,我在ubuntu 14.04上使用netbeans 8.0.2。

public class UserRegistration extends HttpServlet {

    public void init(){
            new File("Directory").mkdirs();
            new File("Directory/Broker").mkdirs();
            new File("Directory/User").mkdirs();
            //these directories are not being created
    }

    protected void processRequest(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {

    }

    @Override
    protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        processRequest(request, response);
    }

    @Override
    public String getServletInfo() {
        return "Short description";
    }

}

0 个答案:

没有答案