JSP page access control and JSP page Access Control

Source: Internet
Author: User

JSP page access control and JSP page Access Control

Access control is implemented based on sessions. What is a session?

Session is a built-in object in JSP. It corresponds to the browser one by one and allows users to store and extract session status information.

Session objects are used to store all information about user sessions.

1. What is session?

(1) A session is a call between the browser and the server,

It contains multiple requests and responses between the browser and the server.

(2) Use the session tracking mechanism provided by Web containers to maintain
User session information, that is, to save different data for different users


2. How is session used?

Common Methods for session objects:

(1) void setAttribute (String key, Object value ):

Store the value of an object in session as a key/value.

Session. setAttribute ("gxs", "admin ");

(2) Object getAttribute (String key ):

Obtain the value of the object stored in the session according to the name.

String name = (String) session. getAttribute ("gxs ");


Code:

<%
If (rs. next () {// if it is a registered user

// Encapsulate the User name and password in the User object

User loginedUser = new User (name, pass );

Session. setAttribute ("gxs", loginedUser );

Response. sendRedirect ("welcome. jsp ");

} Else {

Response. sendRedirect ("login.html ");

}
%>

Here, the user establishes a key-value relationship between gxs and loginedUser for future use.


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.