
If useraction is empty, as it will be initially, then build the url for the login screen, and generate the login screen by invoking the method displayLoginScreen. Code snippet for displayLoginScreen is shown below.

This method calls displayLoginDataFields to generate the data fields for form submission as shown below.

Once this form is submitted, it checks to see whether validation is successful by invoking the method loginUser, which invokes the loginUser method in the StoreAccess Bean as shown below.

Once that is finished, as shown above in the processRequest method code snippet, it builds url's for displaying items and error. Code snippet for the method displayAllItems is shown below.

Code snippet for displayLoginErrorScreen shown below.

All these helper method are being used by the processRequest method, which is acting as a Controller and dispatches the request to the appropriate view, such as the login screen or display items screen.
Now our servlet is complete, as implementation of the rest of the methods is left as an exercise.
Deploy AccessController Servlet :
In order to deploy your servlet, go to LombozJ2EE view.
Select web module OnlineStore > right click > select Deploy module as shown below , make sure the server is running.

Deployment status appears on the console as shown below. If deployment is successful then test your servlet.

Test your Servlet :
Go to your browser and access the servlet using following URL, 'http://localhost:8080/OnlineStore/access'
where 'access' is the url mapping that was assigned while creating the servlet using the Servlet Creation Wizard, and OnlineStore is the web module,where this servlet resides.
The login screen will be displayed. Enter username as 'ANDY' and password as 'PASSWD'. The next screen will be list of items in MyStore as shown below.

We have successfully created a servlet, now let's access this catalogue via a JSP page.
Create JSP Page :
Go To Package Explorer > Expand Web Module node (OnlineStore) > right click and a menu will pop up.
On the pop up menu > New > Select Lomboz JSP Wizard as shown below.

Add file name showItems.jsp as shown below.

Press Next > Menu, the form Set JSP details will appear > Select Add.. under Beans section as shown below.
The menu for Select Beans will appear > Add ID as itemData, Scope as page and Class as ItemData.

Press Ok. Now selected JSP details can be seen after selecting various options as shown below.

Press Finish. A new file named showItems.jsp will be created under the web module OnlineStore as shown below.

Modify Method processRequest in Servlet AccessController :
Now, in order to display all items of MyStore from a JSP page, we have to modify the proccessRequest method in servlet AccessController.
Modify String ITEMS_SCREEN to "/showItems.jsp" as shown below.
![]()
Comment out the call to method displayAllItems in processRequest.
Add a Session attribute named itemsList with values of listItems.






