Because the switch.jsp is specified as the response JSP file in the Login.jsp form, when the user selects the logged-on user in login.jsp, the client sends an HTTP request to the server after the input password submits the form, and the server calls switch.jsp to respond to the request.
The user name and password in the form the data for both components will be passed to the server's switch.jsp via an HTTP request, and the server encapsulates the information in the request object to switch.jsp, so switch.jsp can pass Request.getparameter ( String Paraname) To get the two values.
Imagine that if a login.jsp form has more than 10 data components, the value must be obtained from the corresponding number of request.getparameter () methods in switch.jsp. In addition, if the data is not a field string type, but an integer or floating-point number, because the value returned by the Request.getparameter () method is string, a type conversion is required, which is tedious and error-prone.
JSP allows you to receive data from a Web form in a mapped way through the bean, the bean maps the form's data with this rule: the Bean property name = The form data component name, or all form data fields that are the same as the Bean property name are automatically populated into the bean and the data type conversion is completed. For example, there are two data components in a login.jsp form, one named UserID, and the other is password, which defines a password Bean with the same name UserID and User.java properties. This bean will automatically receive two data component values from the form.
Write User.java
Let's start by writing this user.java Bean, creating User.java in the project, and the code looks like this:
Code Listing 7 User.java
1. Package bookstore;
2.
3. public class User
4. {
5. Private String userid;//User ID
6. Private String password;//Password
7. Private String username;//User name
8. Public String GetPassword () {
9. return password;
10.}
One. Public String GetUserID () {
return userId;
13.}
Public String GetUserName () {
return userName;
16.}
public void SetPassword (String password) {
This.password = password;
19.}
public void Setuserid (String userId) {
This.userid = userId;
22.}
public void Setusername (String userName) {
This.username = UserName;
25.}
26.}
In addition to the UserID and password two property names, there is also a Username property username, the value of this property is not received from the login.jsp form, and when the user name password is validated correctly, the user name is saved from the Datasheet t_user table in this property so that other places can refer to , save and compile this class.
Tips:
You can quickly create User.java code using the JBuilder Bean Express tool, and in general you should create the bean's properties through Bean Express, which not only automatically generates Get/set property access methods, The bean naming specification is also guaranteed.
The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion;
products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the
content of the page makes you feel confusing, please write us an email, we will handle the problem
within 5 days after receiving your email.
If you find any instances of plagiarism from the community, please send an email to:
info-contact@alibabacloud.com
and provide relevant evidence. A staff member will contact you within 5 working days.