Servlet 4.0 behavior changes
The Servlet 4.0 implementation contains behavior changes that might cause an application that was written for another implementation to behave differently or fail when we use the Servlet 4.0 feature.
We can choose between the servlet feature implementations for each server instance with consideration for behavior changes. If the required behavior is contained in the Servlet 4.0 feature only, use the Servlet 4.0 feature. If behavior changes in the Servlet 4.0 feature adversely impact an existing application, use either the Servlet 3.1 feature or Servlet 3.0 feature to preserve the existing behavior for that application. We cannot use two servlet features in the same Liberty server. If two or more servlet features are configured, the program produces an error. If we configure both features, neither servlet feature is loaded.
ServletContext methods
The following ServletContext methods throw a NullPointerException error if the name parameter that is passed is null:- getAttribute(String name)
- getInitParameter(String name)
- setAttribute(String name, Object object)
- setInitParameter(String name, String value)
- getMajorVersion()
- The Servlet 4.0 feature getMajorVersion() API returns 4. The Servlet 3.1 feature and Servlet 3.0 feature getMajorVersion() API returns 3.
- getMinorVersion()
- The Servlet 4.0 feature getMinorVersion() API returns 0. The Servlet 3.1 feature getMinorVersion() API returns 1.
X-Powered-By header
In the Servlet 4.0 feature implementation, the X-Powered-By header is set to Servlet/4.0. In the Servlet 3.1 feature implementation, the X-Powered-By header is set to Servlet/3.1.
Default servlet mapping for servlet requests
A default servlet mapping has a mapping of only the / character. In the Servlet 4.0 implementation, a call to a servlet request getServletPath() method for a default servlet mapping returns the value of the request URI minus the context path, and the getPathInfo() method returns null.
In the Servlet 3.1 and 3.0 implementations, the servlet request getServletPath() method returns an empty string, and the getPathInfo() method returns the value of the request URI minus the context path. To return to the Servlet 3.1 and 3.0 behavior when using the Servlet 4.0 feature, set the following webContainer attribute in server.xml. For more information, see Web Container (webContainer).
<webContainer servletPathForDefaultMapping="false"/>