29.01.2013 Views

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

WebSphere Application Server - IBM Redbooks

SHOW MORE
SHOW LESS

You also want an ePaper? Increase the reach of your titles

YUMPU automatically turns print PDFs into web optimized ePapers that Google loves.

These validators can be turned on and off in the workbench preferences and/or<br />

the project properties. For more information about syntax validation, see “Syntax<br />

validation” on page 92.<br />

12.3 Using Struts in a sample<br />

To illustrate the use of Struts, we will create an administrative login sample that<br />

will allow a user to log in as either a “read access” administrator or a “write<br />

access” administrator.<br />

Let’s assume that up to this point in our application, we have created all the<br />

front-end content for our Web site. We now need to add the back-end content<br />

and the administrative login will be the entry point.<br />

Depending on the user name and password submitted, the user will see a<br />

different administrative maintenance page. The “read access” administrator<br />

(admin1) will see options to view customers and orders. The “write access”<br />

administrator (admin2) will see the options to view, edit, and delete products.<br />

Struts will be used to first validate the user name and password entries and then,<br />

depending on the submitted values, the action will forward the user to the<br />

appropriate page. A Struts action will also be used to log the user out of the<br />

administrative section of the site.<br />

The following JSPs and Java classes are created in this sample:<br />

► login.jsp - provides the interface to log in to the administration page<br />

► LoginForm.java - an instance of this class is used to validate the user input<br />

parameters from the login.jsp page<br />

► LoginAction.java - an instance of this class is used to authenticate the user<br />

► admin1.jsp - displays the options to view a customer or an order<br />

► admin2.jsp - displays the options to view, edit, and delete products<br />

► LogoutAction.java - an instance of this class is used to log the user out of the<br />

administration page and redirect the user to the login page.<br />

Chapter 12. Using Struts 425

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

Saved successfully!

Ooh no, something went wrong!