Advertisement
Guest User

Untitled

a guest
Jan 3rd, 2014
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.14 KB | None | 0 0
  1. package com.sample.struts.action;
  2.  
  3. import java.sql.*;
  4.  
  5. import javax.servlet.http.HttpServletRequest;
  6.  
  7. import org.apache.commons.lang3.StringUtils;
  8. import org.apache.struts2.interceptor.ServletRequestAware;
  9.  
  10. import com.opensymphony.xwork2.Action;
  11. import com.opensymphony.xwork2.ActionSupport;
  12. import com.sample.struts.model.User;
  13. import com.sample.struts.service.LoginService;
  14.  
  15. public class LoginAction extends ActionSupport implements ServletRequestAware{
  16. private String password;
  17. private String email;
  18. private User user;
  19.  
  20. public User getUser() {
  21. return user;
  22. }
  23. public void setUser(User user) {
  24. this.user = user;
  25. }
  26. public String getPassword() {
  27. return password;
  28. }
  29. public void setPassword(String password) {
  30. this.password = password;
  31. }
  32. public String getEmail() {
  33. return email;
  34. }
  35. public void setEmail(String email) {
  36. this.email = email;
  37. }
  38.  
  39. HttpServletRequest request;
  40. @Override
  41. public void setServletRequest(HttpServletRequest arg0)
  42. {
  43. this.request = arg0;
  44.  
  45. String registerBtn = request.getParameter("registerBtn");
  46. String loginBtn = request.getParameter("loginBtn");
  47.  
  48. //if registerBtn is clicked then it's value Register is get stored in registerBtn.
  49. //if not registerBtn is not clicked then variable registerBtn has null.
  50. if(registerBtn != null)
  51. {
  52. //return and call action for register.jsp
  53. }
  54. if(loginBtn != null)
  55. {
  56. //do the login code here
  57. public void validate() {
  58.  
  59. if (StringUtils.isEmpty(getEmail())) {
  60. //email blank
  61. addFieldError("email", "email is empty");
  62. }
  63. if (StringUtils.isEmpty(getPassword())) {
  64. //email password
  65. addFieldError("password", "password is empty");
  66. }
  67. }
  68. }
  69. }
  70. public String execute() {
  71. LoginService loginservice = new LoginService();
  72. user = new User();
  73. user.setEmail(email);
  74. user.setPassword(password);
  75. if (loginservice.verifyLogin(user)) {
  76. System.out.println("verifyuser");
  77. return "success";
  78. } else {
  79. addFieldError("email", "user does not exists");
  80. return "fail";
  81. }
  82.  
  83. }
  84. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement