String city = request.getParameter("city");
String department = request.getParameter("department");
String passwordAgain = request.getParameter("passwordAgain");
/* create new user */
Profile profile = new Profile(username, password, firstName, lastName,
email, phone, street, city, department);
/* instance of database */
DAO dao = DAO.getInstance();
/* all fields must be filled */
if (username.isEmpty() || password.isEmpty() || firstName.isEmpty()
|| lastName.isEmpty() || email.isEmpty() || phone.isEmpty()) {
request.setAttribute("fillAllFields", "<font size=\"3\" "
+ "face=\"arial\" color=\"red\">"
+ "You must fill all the fields! </font>");
RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
rd.forward(request, response);
/* wrong phone format*/
} else if (!phone.matches("[0-9]+")) {
request.setAttribute("wrongPhoneFormat", "<font size=\"3\" "
+ "face=\"arial\" color=\"red\">"
+ "Wrong Phone Format! Must contains only numbers </font>");
RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
rd.forward(request, response);
/* username already exists */
} else if (dao.exists(profile.getId(), username)) {
request.setAttribute("userAlreadyExists", "<font size=\"3\" "
+ "face=\"arial\" color=\"red\">"
+ "Username already exists! Choose another one!</font>");
RequestDispatcher rd = request.getRequestDispatcher("register.jsp");
rd.forward(request, response);