Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- package com.sample.struts.action;
- import java.sql.*;
- import javax.servlet.http.HttpServletRequest;
- import org.apache.commons.lang3.StringUtils;
- import org.apache.struts2.interceptor.ServletRequestAware;
- import com.opensymphony.xwork2.Action;
- import com.opensymphony.xwork2.ActionSupport;
- import com.sample.struts.model.User;
- import com.sample.struts.service.LoginService;
- public class LoginAction extends ActionSupport implements ServletRequestAware{
- private String password;
- private String email;
- private User user;
- public User getUser() {
- return user;
- }
- public void setUser(User user) {
- this.user = user;
- }
- public String getPassword() {
- return password;
- }
- public void setPassword(String password) {
- this.password = password;
- }
- public String getEmail() {
- return email;
- }
- public void setEmail(String email) {
- this.email = email;
- }
- HttpServletRequest request;
- @Override
- public void setServletRequest(HttpServletRequest arg0)
- {
- this.request = arg0;
- String registerBtn = request.getParameter("registerBtn");
- String loginBtn = request.getParameter("loginBtn");
- //if registerBtn is clicked then it's value Register is get stored in registerBtn.
- //if not registerBtn is not clicked then variable registerBtn has null.
- if(registerBtn != null)
- {
- //return and call action for register.jsp
- }
- if(loginBtn != null)
- {
- //do the login code here
- public void validate() {
- if (StringUtils.isEmpty(getEmail())) {
- //email blank
- addFieldError("email", "email is empty");
- }
- if (StringUtils.isEmpty(getPassword())) {
- //email password
- addFieldError("password", "password is empty");
- }
- }
- }
- }
- public String execute() {
- LoginService loginservice = new LoginService();
- user = new User();
- user.setEmail(email);
- user.setPassword(password);
- if (loginservice.verifyLogin(user)) {
- System.out.println("verifyuser");
- return "success";
- } else {
- addFieldError("email", "user does not exists");
- return "fail";
- }
- }
- }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement