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.db.UsersDBConstants;
14import com.bittercode.model.User;
15import com.bittercode.model.UserRole;
16import com.bittercode.service.UserService;
17import com.bittercode.service.impl.UserServiceImpl;
18
19public class SellerLoginServlet extends HttpServlet {
20
21UserService userService = new UserServiceImpl();
22
23public void doPost(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
24PrintWriter pw = res.getWriter();
25res.setContentType(BookStoreConstants.CONTENT_TYPE_TEXT_HTML);
26String uName = req.getParameter(UsersDBConstants.COLUMN_USERNAME);
27String pWord = req.getParameter(UsersDBConstants.COLUMN_PASSWORD);
28try {
29User user = userService.login(UserRole.SELLER, uName, pWord, req.getSession());
30if (user != null) {
31RequestDispatcher rd = req.getRequestDispatcher("SellerHome.html");
32
33rd.include(req, res);
34pw.println(" <div id=\"topmid\"><h1>Welcome to Online <br>Book Store</h1></div>\r\n"
35+ " <br>\r\n"
36+ " <table class=\"tab\">\r\n"
37+ " <tr>\r\n"
38+ " <td><p>Welcome "+user.getFirstName()+", Happy Learning !!</p></td>\r\n"
39+ " </tr>\r\n"
40+ " </table>");
41} else {
42
43RequestDispatcher rd = req.getRequestDispatcher("SellerLogin.html");
44rd.include(req, res);
45pw.println("<div class=\"tab\">Incorrect UserName or PassWord</div>");
46}
47
48} catch (Exception e) {
49e.printStackTrace();
50}
51}
52}