×

Welcome to TagMyCode

Please login or create account to add a snippet.
0
0
 
0
Language: Java
Posted by: Nhan Tran
Added: Aug 8, 2021 3:15 AM
Views: 3665
Tags: no tags
  1. private static final String HOME_PAGE = "SearchAccount";
  2.     static org.apache.log4j.Logger log = org.apache.log4j.Logger.getLogger(AddAccountServlet.class);
  3.  
  4.     /**
  5.      *
  6.      * @param request
  7.      * @param response
  8.      * @throws ServletException
  9.      * @throws IOException
  10.      */
  11.     protected void processRequest(HttpServletRequest request, HttpServletResponse response)
  12.             throws ServletException, IOException {
  13.         response.setContentType("text/html;charset=UTF-8");
  14.         String username = request.getParameter("txtUsername");
  15.         String password = request.getParameter("txtPassword");
  16.         Account a = new Account();
  17.         try {
  18.             if (!"".equals(password) && !"".equals(username)) {
  19.                 a.setPassword(password);
  20.                 a.setUsername(username);
  21.                 AccountDAO dao = new AccountDAO();
  22.                 dao.save(a);
  23.             }
  24.         } catch (SQLException | NamingException ex) {
  25.             log.warn(ex.getClass().getSimpleName() + "_AddAccountServlet" + "_Exception :  " + ex.getMessage());
  26.         } finally {
  27.             response.sendRedirect(HOME_PAGE);
  28.         }
  29.     }