Introduction to functions of Servlet 2.4

Source: Internet
Author: User

Some new functions have been added to the latest Servlet version 2.4 of J2EE1.4. The following describes the main common functions.

1. XML Schema definition Web query deployment description file

In versions earlier than Servlet 2.3, DTD is used as the definition of the deployment description file. The web. xml format is as follows:

 
 
  1. <?xml version="1.0" encoding="IS0-8859-1"?> 
  2. <!DOCTYPE web-app  
  3. PUBLIC "-//sunMicrosystems,Inc.//DTD WebApplication 2.3f//EN"  
  4. "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd"> 
  5. <web-app> 
  6.  .......  
  7. </web-app> 

For the first time, Servlet 2.4 uses the XML Schema definition as the deployment description file, which makes it easier for Web containers to verify the web. xml syntax. At the same time, XML Schema provides better scalability. Its web. xml format is as follows:

 
 
  1. <?xml version="1.0" encoding="UTF-8"?> 
  2. <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" 
  3. xmlns:workflow="http://www.workflow.com" 
  4. xmins:xsi="http://www.w3.org/2001/XMLSchema-instance" 
  5. xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee  
  6. http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"> 
  7. .........  
  8. </web-app> 

Although there are differences between the first few lines of the two versions shown above, the method for setting web Components in Servlet 2.4 Web. xml is roughly the same as that in Servlet 2.3.

2. Servlet Request listener

Servlet 2.4 adds the ServletRequest listener to the event listener, including ServletRequestListener, ServletRequestAttributeListener, and other related classes. These classes can be used to manage and control events related to the ServletRequest action. The following program shows the structure of a typical ServletRequest listener.

 
 
  1. import javax.setvlet.ServletContext;  
  2. import javax.servlet.ServletRequestListener;  
  3. import javax.servlet.ServletRequestAttributeListener;  
  4. import javax.servlet.http.HttpServletRequest;  
  5. import iava.io.*;  
  6. import java.util.Locale;  
  7. public final class RequestListenerimplements 
    SerVletRequestListener,  
  8. ServletRequestAttributeListener,ServletContextListener{  
  9. ........  
  10. public void requestlnitialized(javax.servlet.
    ServletRequestEvent event){  
  11. ........  
  12. }  
  13. public void attributeAdded(javax.servlet.
    ServletRequestAttributeEvent event){  
  14. ........  
  15. }  
  16. public void attributeRemoved(javax.servlet.
    ServletRequestAttributeEvent event){  
  17. ........  
  18. }  
  19. public void attributeReplaced(javax.servlet.
    ServletRequestAttributeEvent event){  
  20. ........  
  21. }  
  22. public void attributeDestroyed(javax.servlet.
    ServletRequestAttributeEvent event){  
  23.  ........  
  24.  }  

3. Request Dispatcher changes

Servlet 2.4 Web programs enhance the filter and request dispatcher functions, so that the filter can filter Web requests conditionally according to the methods used by the request dispatcher (request dispatcher. Programmers can use elements in web. xml to set filter conditions (1 ):

Set element Filters

◆ The filter takes effect only when the request comes directly from the customer. The filter corresponds to the REQUEST condition.
◆ The forward condition is used or defined only when a request is transferred to a Web component by a request distributor using the FORWARD () method.
◆ Similarly, when a request is transferred to a Web component by a request distributor using the include () method (or defined), the request is called the INCLUDE condition.
◆ The ERROR condition is called only when a request is transferred to a Web component by a request distributor using the "ERROR page" mechanism.
◆ The fifth filter can be a combination of the above four conditions.

  1. New Servlet and JSP features
  2. Talking about Servlet Web Server
  3. Implement Servlet applications in Weblogic
  4. Communication between Servlet and CGI
  5. Use MIDlet to activate Servlet

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.