@Override
    protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
        try {
            PrintWriter out = response.getWriter();
            DiskFileItemFactory factory = new DiskFileItemFactory();
            ServletFileUpload fileUpload = new ServletFileUpload(factory);
            List items = fileUpload.parseRequest(request);
            Iterator ir = items.iterator();
            while(ir.hasNext()) {
                FileItem item = (FileItem)ir.next();
                if(item.isFormField()) {
                    String fieldName = item.getFieldName();
                    if(fieldName.equals("username")) {
                        userName = item.getString();
                        userPath = dbPath + userName;
                        File file = new File(userPath);
                        if(file.exists()) {
                            out.println("Username already exists.");
                            success = false;
                        }
                        else {
                            new File(userPath).mkdir();
                            new File(userPath + dataPath).mkdir();
                            new File(userPath + imagePath).mkdir();
                            new File(userPath + xmlPath).mkdir();
                            File codeFile = new File(userPath + dataPath + "imagecode");
                            codeFile.createNewFile();
                            BufferedReader in = new BufferedReader(new FileReader(codeFile));
                            PrintWriter writer = new PrintWriter(codeFile);
                            writer.print(imageCode);
                            writer.close();
                        }
                    }
                    if(fieldName.equals("password") && success) {
                        passWord = item.getString();
                        File passwordFile = new File(userPath + dataPath + "password");
                        passwordFile.createNewFile();
                        BufferedReader in = new BufferedReader(new FileReader(passwordFile));
                        PrintWriter writer = new PrintWriter(passwordFile);
                        writer.print(passWord);
                        writer.close();
                        usr++;
                        getServletContext().setAttribute("usr" + usr, "usr");
                    }
                }
            }
        }
        catch (FileUploadException ex) {Logger.getLogger(Signup.class.getName()).log(Level.SEVERE, null, ex);}
        if(success){response.sendRedirect(response.encodeRedirectURL("home.jsp?usr=" + userName));}
        else {success = true;}
    }