December 27, 2006 on 6:31 am | In Java |
JavaSercer Pages Next, a scriptlet is used to ensure that both the username and the password are passed as parameters. The same getParameter( ) method used in Example 10.2 is used here to retrieve the parameter values. If one or both parameters are missing, the action redirects back to the login page again. Here you see how the errorMsg parameter used in the login.page gets its value. If the request contains both parameters, one of the database actions introduced in Chapter 9 is used to see if there’s a user with the specified name and password in the database: SELECT * FROM Employee WHERE UserName = ? AND Password = ? <% if (empInfo.size( ) == 0) { %> If the query doesn’t match a registered user (i.e., empInfo.size( ) returns 0), an action redirects back to the login page with an appropriate error message. Otherwise, the processing continues. 10.2.3.1 Creating the validation object If a user is found, the single row from the query result is extracted and the column values are used to populate the single value properties of an EmployeeBean object. An EmployeeBean has the properties shown in Table 10.2. Table 10.2, Properties for com.ora.jsp.beans.emp.EmployeeBean Property Name Java Type Access Description userName String read/write The employee’s unique username firstName String read/write The employee’s first name lastName String read/write The employee’s last name dept String read/write The employee’s department name empDate String read/write The employee’s employment date in the format yyyy-MM-dd emailAddr String read/write The employee’s email address projects String[] read/write A list of all projects the employee is involved in The bean is named validUser and placed in the session scope using the standard action. All properties are set to the values returned from the database using actions: <% Row oneRow = (Row) empInfo.firstElement( ); %> ‘ /> ‘ /> ‘ /> page 139
Hint: If you are looking for very good and affordable webspace to host and run your j2ee hosting application check Sandzak.com j2ee web hosting services
Sorry, the comment form is closed at this time.