Servlet day 4

Source: Internet
Author: User

The same account can only log on once:
The account is unique, and the account (list/set) is logged on at the same time)
You need to determine whether the current account already exists during each login.
Login not allowed if yes
If not, log on.

Httpservletrequest: A group of requests and responses
Two business flows jump,
If forward is used:
Req. getparameter () GET parameters on the page
Req. getattribute () obtains shared objects between resources.
If sendredirect is used
The request object cannot share data.

Httpsession: a client receives a series of related requests and responses.
Multi-group business flow jump:
If forward is used:
Session. getattribute () gets shared objects between resources.
If sendredirect is used
Session. getattribute () must be used ()

Servletcontext: entire Web Application
Multiple business processes
Information set by a user to access other users
Data accessed by all users in the current system

========================================================== ========================
Setattribute (string name, object O );
Getattribute (string name): Object O;
Removeattribute (string name );
========================================================== ========================

The role of session:
Identifies the current client
A group of related operations can only belong to the current user

The underlying implementation mechanism of the session:
COOKIE: A small file generated by the server, sent to the client, and saved on the client to describe customer information.
1. When the customer first accesses the server, the server creates a cookie for the current user.
2. Server saving information: Cookie ------- user
3. the server sends the generated cookie object to the client.
4. The client obtains the cookie information and stores it in a local file.

5. The client must read the cookie information and send the request to the server.
6. The server receives the request and the cookie corresponding to the client.
7. The server uses the obtained cookie to search for the user information in the internally saved correspondence. Return to customer

JSESSIONID = a17683eeaa6e6b1568fecc942bedae57
URL rewrite:
Append parameter information to all request URLs. For example:
ADD? JSESSIONID = a17683eeaa6e6b1568fecc942bedae57
Delete? JSESSIONID = a17683eeaa6e6b1568fecc942bedae57

Url = "add ";
URL + = Req. getsession (). GETID ();
==>
Resp. encodeurl ("add"): String => Add? JSESSIONID = a17683eeaa6e6b1568fecc942bedae57
Resp. encoderedirecturl ("add ")
Hidden:
<Input type = "hidden" name = "JSESSIONID" value = "a17683eeaa6e6b1568fecc942bedae57">

Addcookie ---> addcookieservlet ----> index.html
Index.html ---> showcookieservlet

Listener:
Observer Mode

Servletrequestlistener listens to the creation and destruction of servletrequest
Event source servletrequest
Event object creation/destruction
Event listening servletrequestlistener

Httpsessionlistener listens to the creation and destruction of httpsession
Servletcontextlistener listens to creation and destruction of servletcontext

Listener programming:
1. Compile the listener class, implement corresponding interfaces, and implement two internal methods.
2. Configure the listener class for Web Container Management
<Listener>
<Listener-class>
Listener. myservletcontextlistener
</Listener-class>
</Listener>

Interface function:
1. Concurrent Development by programmers
2 Coupling
Istumgmtdao Dao = new stumgmtdaoimpl ();
Coupling in the source code of each servlet processing class makes maintenance difficult
Solution:
Dao should be an object shared by the entire application.
That is, save the DaO object in the range of servletcontext
When should Dao be created:
When the project is started, Dao is created.
If the project is closed, Dao is destroyed.
===" Servletcontextlistener

 

* 1 first page previous page next page last page
Rownum

2 1 2 3... 18 19 20 ___ jump

 

 

 

 

 

 

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.