Access control for JSP pages

Source: Internet
Author: User

Access control is done based on the session, so what is the session?

Session is a built-in object in the JSP that corresponds to browser one by one, allowing the user to store and extract session state information

Session objects are used to store all information about a user's session

1. What is a session?

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

It contains multiple requests between the browser and the server, the response process

(2) using the session tracking mechanism provided by the Web container, you can maintain each
User's session information, that is, to save different data for different users


How is the 2.session used?

Common methods for session objects:

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

Stores the value of an object in the session as a key/value

Session.setattribute ("GXs", "admin");

(2) Object getattribute (String key):

Gets the value of the stored object in the session according to the name

String name = (string) session.getattribute ("GXs");


Specific code:

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

Encapsulates the user name and password in the Users object

User Logineduser = new User (name, pass);

Session.setattribute ("GXs", Logineduser);

Response.sendredirect ("welcome.jsp");

} else {

Response.sendredirect ("login.html");

}
%>

Here the user put GXS and Logineduser set up a key value relationship, convenient for later use.


Access control for JSP pages

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.