Get the App
SLTechnology News&Howtos  ›  Development  › 

What are the features of Servlet version 2.4

Shulou Source: shulou.com Published: 2022-06-02 05:09:29 09月23日 Update

This article introduces the relevant knowledge of "Servlet 2.4 version features". In the actual case operation process, many people will encounter such difficulties. Next, let Xiaobian lead you to learn how to deal with these situations! I hope you can read carefully and learn something!

1. XML Schema Definition Web Query Deployment Description File

Servlet versions prior to 2.3 used a DTD as the definition of the deployment description file, and its web.xml format was as follows:

.......

Servlet version 2.4 *** uses XML Schema definitions as deployment description files, making it easier for Web containers to verify web.xml syntax. XML Schema also provides better extensibility, and its format in web.xml is as follows:

.........

Although the first few lines above show differences between the two versions, Web artifacts in Servlet version 2.4 program web.xml are set up in much the same way as Servlet version 2.3.

2. Servlet Request Listeners

Servlet version 2.4 adds ServletRequest listeners to the event listener, including ServletRequestListener, ServletRequestAttributeListener, and other related classes. These classes can be used to manage and control events related to ServletRequest actions. 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 Change

Servlet version 2.4 of the Web program enhances the cooperation between filter and request dispatcher so that the filter can conditionally filter Web requests based on the method used by the request dispatcher. Programmers can set the conditions under which filters work by using elements in web.xml (Figure 1 below):

Set filters for elements

◆ The filter takes effect only if the request comes directly from the customer, corresponding to the REQUEST condition.

Only when a request is forwarded to a Web artifact by a request dispatcher using the forward() method (adopted or defined), the corresponding condition is called FORWARD.

Similarly, only when a request is forwarded to a Web artifact by a request dispatcher using the include() method (adopted or defined), the corresponding condition is called INCLUDE.

Only when a request is forwarded to a Web artifact by a request dispatcher using the Error Information Page mechanism is the ERROR condition.

The fifth filter condition can be a combination of the above four conditions.

"Servlet version 2.4 features what" content is introduced here, thank you for reading. If you want to know more about industry-related knowledge, you can pay attention to the website. Xiaobian will output more high-quality practical articles for everyone!

Tags: Conditions methods filters only artifacts listeners listeners functions files programs events actions elements content more formats versions knowledge relevant practical Apple Docker Huawei Linux macOS MariaDB Microsoft MySQL NVidia OPPO Reno Redmi MySQL Microsoft MariaDB NVidia