Advertisement
Guest User

Untitled

a guest
Oct 1st, 2016
97
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.55 KB | None | 0 0
  1. public class User {
  2.  
  3. private int userId;
  4. private int user_type;
  5. private String username;
  6. private String password;
  7.  
  8. public User(int id, int user_type, String username, String password) {
  9. super();
  10. this.userId = id;
  11. this.user_type = user_type;
  12. this.username = username;
  13. this.password = password;
  14. }
  15.  
  16. public int getUserId() {
  17. return userId;
  18. }
  19. public void setUserId(int userId) {
  20. this.userId = userId;
  21. }
  22.  
  23. public int getUser_type() {
  24. return user_type;
  25. }
  26.  
  27. public void setUser_type(int user_type) {
  28. this.user_type = user_type;
  29. }
  30.  
  31. public String getUsername() {
  32. return username;
  33. }
  34.  
  35. public void setUsername(String username) {
  36. this.username = username;
  37. }
  38.  
  39. public String getPassword() {
  40. return password;
  41. }
  42.  
  43. public void setPassword(String password) {
  44. this.password = password;
  45. }
  46.  
  47. }
  48.  
  49. public class Customer extends User{
  50.  
  51. private String cartId;
  52.  
  53. public Customer(int id, int user_type, String username, String password) {
  54. super(id, user_type, username, password);
  55. // TODO Auto-generated constructor stub
  56. }
  57.  
  58. public String getCartId() {
  59. return cartId;
  60. }
  61.  
  62. public void setCartId(String cartId) {
  63. this.cartId = cartId;
  64. }
  65. }
  66.  
  67. protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
  68. // TODO Auto-generated method stub
  69. String username = request.getParameter("username");
  70. String password = request.getParameter("password");
  71. boolean userDoesNotExist = false;
  72.  
  73. User user = ServiceFactory.userService().getUser(username);
  74. System.out.println(user.getPassword() + " " + user.getUsername());
  75.  
  76. if(user != null){
  77. if(user.getUser_type() == 1){
  78. String cartId = ServiceFactory.customerService().getCartId(user.getUserId());
  79. Customer customer = (Customer) user;
  80. customer.setCartId(cartId);
  81.  
  82. request.getSession().setAttribute("customer", customer);
  83. response.sendRedirect("customer");
  84. }else{
  85.  
  86. }
  87. }else{
  88. userDoesNotExist = true;
  89.  
  90. request.setAttribute("userDoesNotExist", userDoesNotExist);
  91. request.setAttribute("username", username);
  92. RequestDispatcherManager.dispatch(this, "/login.jsp", request, response);
  93. }
  94. }
  95.  
  96. java.lang.ClassCastException: com.qbryx.domain.User cannot be cast to com.qbryx.domain.Customer
  97. com.qbryx.servlets.LoginServlet.doPost(LoginServlet.java:50)
  98. javax.servlet.http.HttpServlet.service(HttpServlet.java:648)
  99. javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
  100. org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement