Because login. in the jsp form, the switch is specified through the action attribute. jsp is the JSP file in the response. select a logon user in jsp. After entering the password to submit the form, the client sends an HTTP request to the server, that is, the server calls switch. jsp to respond to this request.
The user name and password data in the form will be sent to the server switch through an HTTP request. jsp. The server encapsulates the information in the request object and sends it to the switch. jsp, so switch. jsp can be accessed through request. getParameter (String paraName) to obtain the two values.
String userId = request. getParameter ("userId ");
String password = request. getParameter ("password ");
Imagine if there are more than 10 data components in the form of login. jsp, the value must be obtained through the request. getParameter () method of the corresponding number in switch. jsp. In addition, if the data is not of the field string type, but an integer or floating point number, because of the request. the value returned by the getParameter () method is String and type conversion is required. This kind of work is not only monotonous, but also error-prone.
JSP allows you to receive webpage form data through Bean ing. Bean maps form data with this rule: Bean attribute name = form data component name, that is, all form data fields with the same Bean property names are automatically filled in the Bean and converted into data types. Such as login. the jsp form has two data components, one named userId and the other named password, which define a User with the same name and password attribute. java Bean, which can automatically receive the values of two data components in the form.
Compile User. java
Compile the Bean of User. java and create User. java in the project. The code is as follows:
Code List 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 .}
11. public String getUserId (){
12. return userId;
13 .}
14. public String getUserName (){
15. return userName;
16 .}
17. public void setPassword (String password ){
18. this. password = password;
19 .}
20. public void setUserId (String userId ){
21. this. userId = userId;
22 .}
23. public void setUserName (String userName ){
24. this. userName = userName;
25 .}
26 .}
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.