test
Форк от lirfrnk/test
1package servlets;
2
3import java.io.IOException;
4import java.io.PrintWriter;
5
6import javax.servlet.RequestDispatcher;
7import javax.servlet.ServletException;
8import javax.servlet.http.HttpServlet;
9import javax.servlet.http.HttpServletRequest;
10import javax.servlet.http.HttpServletResponse;
11
12import com.bittercode.constant.BookStoreConstants;
13import com.bittercode.constant.ResponseCode;
14import com.bittercode.constant.db.UsersDBConstants;
15import com.bittercode.model.User;
16import com.bittercode.model.UserRole;
17import com.bittercode.service.UserService;
18import com.bittercode.service.impl.UserServiceImpl;
19
20public class CustomerRegisterServlet extends HttpServlet {
21
22UserService userService = new UserServiceImpl();
23
24public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
25PrintWriter pw = res.getWriter();
26res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML);
27
28String pWord = req.getParameter(UsersDBConstants.COLUMN_PASSWORD);
29String fName = req.getParameter(UsersDBConstants.COLUMN_FIRSTNAME);
30String lName = req.getParameter(UsersDBConstants.COLUMN_LASTNAME);
31String addr = req.getParameter(UsersDBConstants.COLUMN_ADDRESS);
32String phNo = req.getParameter(UsersDBConstants.COLUMN_PHONE);
33String mailId = req.getParameter(UsersDBConstants.COLUMN_MAILID);
34User user = new User();
35user.setEmailId(mailId);
36user.setFirstName(fName);
37user.setLastName(lName);
38user.setPassword(pWord);
39user.setPhone(Long.parseLong(phNo));
40user.setAddress(addr);
41try {
42String respCode = userService.register(UserRole.CUSTOMER, user);
43System.out.println(respCode);
44if (ResponseCode.SUCCESS.name().equalsIgnoreCase(respCode)) {
45RequestDispatcher rd = req.getRequestDispatcher("CustomerLogin.html");
46rd.include(req, res);
47pw.println("<table class=\"tab\"><tr><td>User Registered Successfully</td></tr></table>");
48} else {
49RequestDispatcher rd = req.getRequestDispatcher("CustomerRegister.html");
50rd.include(req, res);
51pw.println("<table class=\"tab\"><tr><td>" + respCode + "</td></tr></table>");
52pw.println("Sorry for interruption! Try again");
53}
54} catch (Exception e) {
55e.printStackTrace();
56}
57}
58}