Java EE Servlet Knowledge Point

Source: Internet
Author: User

1. How to obtain RequestDispatcher
RequestDispatcher objects can be obtained from the request or web context, although two methods are slightly different. A request can take a relative path
(that is, not starting with "/") as a parameter, and the Web context requires an absolute path.
RequestDispatcher dispatcher = Getservletcontext (). Getrequestdispatcher ("/banner");
if (Dispatcher!= null)
Dispatcher.include (request, response);

2.Forward (Dispatcher.forward (request, response) or <jsp:forward>) after the occurrence, how to obtain the relevant parts of the previous URL
When a request is forward to another request, the original URI and its components are saved as request attributes:
Javax.servlet.forward. [Request-uri|context-path|servlet-path|path-info|query-string]

How to obtain information about the contained pages after 3.Include (request, response, or <jsp:include>) occurs dispatcher.include
When a page is included in another page, you can get the original parent URL by Request.getrequesturl (), and for the included page information, you can pass
Get the following properties from the request:
Javax.servlet.include. [Request-uri|context-path|servlet-path|path-info|query-string]

4.session.invalidate and Session.reomveattribute differences:
       RemoveAttribute is the binding object that deletes the specified name from the session, which means that when you call GetAttribute (Stringname) After calling this method, you cannot get the
        a bound object that specifies the name, the return value is null when the GetAttribute method is invoked, but the session still exists. Invalidate is to revoke this session object, to unbind all objects that are bound to the
       this sessions object, and this time the call to GetAttribute method throws " Session already invlidated! " Abnormal.
       Note: There are two cases of Session destruction: timeout and manual Destruction, (1) Tomcat can set the timeout by adding the following configuration in Web.xml
       <session-config><session-timeout>30</session-timeout> </session-config>; (2) manual destruction refers to the direct invocation of its invalidate side
       law, This method actually calls the expire method to manually set it to timeout invalidate is to invalidate this session object, call Request.getsession (false)
        returns null;

The application of 5.httpservletrequest.encodeurl in the session tracking
The Encodeurl (URL) method is primarily used to implement session tracing through the mechanism of URL rewriting, which implements the following logic:
(1) First, determine whether the current Web component is session enabled, and return the parameter URL directly if session is not enabled.
(2) again to determine whether the client browser support cookies, if you support cookies, directly return the parameter URL, if you do not support cookies, in the parameter URL to add
Session ID information, and then return the modified URL.
For robust session tracking, all URLs distributed in the servlet should go through this method, otherwise the URL rewrite mechanism will not be able to browser that does not support cookies
To use, as for example:
If the browser's cookie is disabled, the encoded URL is similar: http://localhost:8080/bookstore1/cashier;jsessionid=c0o7fszeb1
If the browser's cookie is enabled, the encoded URL is similar: http://localhost:8080/bookstore1/cashier

6. Terminate servlet (TBD)

Http://download.oracle.com/javaee/5/tutorial/doc/bnags.html

       http://hi.baidu.com/clisdena/blog/item/0350621fb20df0cda786698e.html

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.