Java Web Learning notes-JSP login case

Source: Internet
Author: User

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.

Related Article

Contact Us

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.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.