Java Reference
In-Depth Information
7. user.setPassword(getPassword());
8. setUser(user);
9. if (dao.isUserAllowed(user)) {
11. setCategoryList(dao.findAllCategories());
12. session.put("username", username);
13. session.put("categoryList", getCategoryList());
14. executelogin = "success";
15. }
16. else {
17. addActionError(getText("error.login"));
18. return "error";
19. }
20. // return result;
21. return "executelogin";
22. }
Figure 4-24 illustrates the USER table.
Figure 4-24. USER table
Line 9 : The user is authenticated against the database. As you can see in the
Line 9 replaces the hard-coded username and password in the Listing 4-31 by
invoking isUserAllowed() on the DAO The isUserAllowed() method selects
the username and password from the USER table (as shown in Figure 4-24 ) in
the resultset based on the username and password entered in the login form.
Line 11-14 : If the user is valid, categories are retrieved from the database, and
the list of categories is stored in the session.
Lines 16-19 : Line 16 sets the valid boolean variable to true if the resultset
contains the username and password If the user is not valid, the String error is
Displaying Categories Retrieved from the Database
Listing 4-41 illustrates the menu that shows the categories returned from the database. In Listing 4-40,
you retrieved the categories and stored them in the session for a valid user. These categories will be
displayed in menu.jsp .
Search WWH ::

Custom Search