29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

Create successful ePaper yourself

Turn your PDF publications into a flip-book with our unique Google optimized e-Paper software.

Example 12-13 LoginAction class<br />

public class LoginAction extends Action {<br />

public ActionForward execute(<br />

ActionMapping mapping,<br />

ActionForm form,<br />

HttpServletRequest request,<br />

HttpServletResponse response)<br />

throws Exception {<br />

ActionErrors errors = new ActionErrors();<br />

//return value<br />

ActionForward forward = new ActionForward();<br />

//Get the Form to read the user's input<br />

LoginForm loginForm = (LoginForm) form;<br />

String userName = loginForm.getUsername();<br />

String password = loginForm.getPassword();<br />

// Write logic determining how the user should be forwarded.<br />

// For simplicity, the user input is checked against a known set<br />

// of userid/passwords. In a business application, the<br />

// the username/password validation is done against an underlying<br />

// database storing users' information.<br />

//START LOGIN LOGIC<br />

if (userName.equals("admin1") && password.equals("admin1"))<br />

{<br />

forward = mapping.findForward("admin1page");<br />

}<br />

else if (userName.equals("admin2") && password.equals("admin2"))<br />

{<br />

forward = mapping.findForward("admin2page");<br />

}<br />

else<br />

{<br />

errors.add(ActionErrors.GLOBAL_ERROR, new<br />

ActionError("error.password.mismatch"));<br />

forward = mapping.findForward("failure");<br />

}<br />

//END LOGIN LOGIC<br />

//Report any errors we have discovered. These errors are displayed<br />

//on the destination page respresented by the 'forward' object<br />

if(!errors.isEmpty())<br />

446 <strong>IBM</strong> <strong>WebSphere</strong> <strong>Application</strong> <strong>Server</strong> - Express V5.0.2 Developer Handbook

Hooray! Your file is uploaded and ready to be published.

Saved successfully!

Ooh no, something went wrong!