/*
* To change this template, choose Tools | Templates
* and open the template in the editor.
*/
package controller;
import formbeans.signin;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import model.user;
import model.userDAO;
import org.apache.struts.action.ActionErrors;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;
import org.apache.struts.action.ActionMessage;
/**
*
* @author Arvind
*/
public class adminlogin extends org.apache.struts.action.Action {
/* forward name="success" path="" */
private static final String SUCCESS = "success";
/**
* This is the action called from the Struts framework.
* @param mapping The ActionMapping used to select this instance.
* @param form The optional ActionForm bean for this request.
* @param request The HTTP Request we are processing.
* @param response The HTTP Response we are processing.
* @throws java.lang.Exception
* @return
*/
@Override
public ActionForward execute(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws Exception {
ActionErrors errors = new ActionErrors();
HttpSession session = request.getSession();
saveErrors(request, errors);
signin data = (signin) form;
userDAO admin = new userDAO();
try {
user u = admin.admin(data.getUsername(), data.getPassword());
if (u.getUsername().equals(data.getUsername()) && u.getPassword().equals(data.getPassword())) {
System.out.println("user valid");
session.setAttribute("username", u.getUsername());
return mapping.findForward(SUCCESS);
} else {
System.out.println("user valid");
throw new RuntimeException();
}
} catch (Exception e) {
errors.add("invalid", new ActionMessage("error.record"));<-----this error is not diplayed in the form,when forward happens
return mapping.findForward("error");
}
}
}