@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
req.setCharacterEncoding("UTF-8");
final String user = req.getParameter("user");
final ChatUsers users = (ChatUsers) getServletContext().getAttribute("users");
ChatUser newUser = new ChatUser();
newUser.setUser(user);
String message = null;
if (users.getUsers().containsKey(newUser)){
message = String.format("User \"%s\" already exists", user);
} else {
newUser.setPassword(req.getParameter("pass"));
users.getUsers().put(newUser, new ArrayList<String>());
message = String.format("User \"%s\" created", user);
}
req.setAttribute("message", message);
final RequestDispatcher rd = getServletContext().getRequestDispatcher("/register.jsp");
rd.forward(req, resp);