Below we write the generated file
First Logonform.java file
Public ActionerRors Validate
ActionMapping mapping,
HttpservletRequest request) {
ActionerRors Errors = Super.Validate (Mapping, Request);
IF (errors == null) {
ERRORS = New ActionerRORS ();
}
IF (Password == Null) || (Password.trim (). Length () == 0)) {
Errors.Add ("Password", New ActionError ("Password"));
}
IF ((Username == Null) || (username.trim (). Length () == 0)) {
Errors.Add ("UserName", New Actionerror ("UserName");
}
Return Errors;
}
Modify the Action class
Public ActionForward Execute (ActionMapping Mapping, Actionform Form,
HttpservletRequest Request, httpservletResponse response) {
LogonForm logonform = (logonform) form;
Session s = null;
Try {
S = yjbasehbm.currentsession ();
} catch (hibernateException e) {
E.PrintStackTrace ();
ActionerroS Errors = new actionerrors ();
Errors.Add ("hbm.session.error",
NEW ActionError ("HBM.Session.Error");
SaveerRors (Request, Errors);
Return mapping.findforward ("failure");
}
Try {
Query Q = S.CreateQuery ("from userinfo ui where ui.username =: user and password =: password");
Q.Setstring ("User", Logonform.getuserName ());
Q.setString ("password", logonform.getpassword ());
System.out.println (Q.Tostring ());
Iterator it = q.Iterage ();
IF (it.hasnext () == false) {
ActionerroS Errors = new actionerrors ();
Errors.Add ("No.user",
New ActionError ("No.user"));
SaveerRors (Request, Errors);
Return mapping.findforward ("failure");
}
Yjbasehbm.closesession ();
} catch (hibernateException e) {
E.PrintStackTrace ();
ActionerroS Errors = new actionerrors ();
Errors.Add ("HBM.Session.Query", New ActionError ("HBM.Session.Query));
SaveerRors (Request, Errors);
Return mapping.findforward ("failure");
} catch (exception E1) {
E1.PrintStackTrace ();
ActionerroS Errors = new actionerrors ();
Errors.Add ("HBm.Session.Query",
New Actionerror ("HBM.Session.Query)));
SaveerRors (Request, Errors);
Return mapping.findforward ("failure");
}
Return mapping.findforward ("Success");
}
Logon.jsp and struts-config.xml configuration modification see download files