Four pages are required: the login. jsp page for data submission, the checklogin. jsp page for data processing, the welcome. jsp page for Displaying results, and the error. jsp page
Basic knowledge:
The form in login. jsp uses <form action = "checklogin. jsp" method = "post">... </Form> statement to submit user data to checklogin. jsp;
Checklogin. jsp captures user data through the statement stringusername = request. getparameter ("username;
Checklogin. JSP uses <JSP: Forward page = "welcome. JSP "> </jsp: Forward> jump to the result page Welcom. in JSP, you can also use response. senredirect ("welcome. JSP.
Keep user logon information: Session. setattribute ("username", username); or request. getsession (). setattribute ("username", username );
Get userbean object:
<JSP: usebeanid = "user" class = "login. userbean" Scope = "page">
<JSP: setpropertyname = "user" property = "*"/>
</Jsp: usebean>
Create an object ID = "user" for this class by operating userbean in JavaBean mode. Fill in the form data submitted by the user with this object and set the effective range to page, that is, a request.
Specific implementation process:
1>
In the login. the JSP page submits a form that contains username and password data, and then the checklogin. JSP: <form action = "checklogin. JSP "method =" Post ">... </Form>
2>
The username and password data submitted on the page are directly encapsulated into an instance (object) of userbean, correspondingCodeIs:
<% @ Pageimport = "login. userbean" %>
<JSP: usebeanid = "user" class = "login. userbean" Scope = "page">
<JSP: setpropertyname = "user" property = "*"/>
</Jsp: usebean>
3> On the checklogin. jsp page, call the user. cheklogin () method to access the database verification data;
4> execute forwarding to separate the database access code from the JSP page.