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:
- <?xml version="1.0" encoding="IS0-8859-1"?>
- <!DOCTYPE web-app
- PUBLIC "-//sunMicrosystems,Inc.//DTD WebApplication 2.3f//EN"
- "http://java.sun.com/j2ee/dtds/web-app_2.3.dtd">
- <web-app>
- .......
- </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:
- <?xml version="1.0" encoding="UTF-8"?>
- <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
- xmlns:workflow="http://www.workflow.com"
- xmins:xsi="http://www.w3.org/2001/XMLSchema-instance"
- xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
- http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
- .........
- </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.
- import javax.setvlet.ServletContext;
- import javax.servlet.ServletRequestListener;
- import javax.servlet.ServletRequestAttributeListener;
- import javax.servlet.http.HttpServletRequest;
- import iava.io.*;
- import java.util.Locale;
- public final class RequestListenerimplements
SerVletRequestListener,
- ServletRequestAttributeListener,ServletContextListener{
- ........
- public void requestlnitialized(javax.servlet.
ServletRequestEvent event){
- ........
- }
- public void attributeAdded(javax.servlet.
ServletRequestAttributeEvent event){
- ........
- }
- public void attributeRemoved(javax.servlet.
ServletRequestAttributeEvent event){
- ........
- }
- public void attributeReplaced(javax.servlet.
ServletRequestAttributeEvent event){
- ........
- }
- public void attributeDestroyed(javax.servlet.
ServletRequestAttributeEvent event){
- ........
- }
- }
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.
- New Servlet and JSP features
- Talking about Servlet Web Server
- Implement Servlet applications in Weblogic
- Communication between Servlet and CGI
- Use MIDlet to activate Servlet