uCosminexus Application Server, Web Container Functionality Guide

[Contents][Glossary][Index][Back][Next]

6.2.5 Precautions related to added and changed specifications in the Servlet 2.4 specifications

This subsection describes the precautions for using the specifications that has been added and changed in Servlet 2.4 on the Application Server. For details on the Servlet 2.4 specifications and Servlet 2.3 specifications, see the respective specifications (Servlet 2.4 specifications and Servlet 2.3 specifications).

Organization of this subsection
(1) Using X-Powered-By header
(2) Notes on using the forward method of the java.servlet.RequestDispatcher interface
(3) Deprecated javax.servlet.SingleThreadModel interface
(4) setLocale method of the javax.servlet.ServletResponse interface
(5) javax.servlet.UnavailableException
(6) sessionDestroyed method of the javax.servlet.http.HttpSessionListener interface
(7) sendRedirect method of the javax.servlet.http.HttpServletResponse interface
(8) Status message of HTTP status code 302
(9) HttpSession timeout during the execution of the service method of the servlet
(10) Control when exception occurs in the listener
(11) Commonly used external library (Extension)
(12) Using the cross context between the Web applications with different servlet versions
(13) When calling Session Bean of EJB 3.0 from the Web application of Servlet 2.4

(1) Using X-Powered-By header

The X-Powered-By header added in the Servlet 2.4 specifications is not added to the response.

(2) Notes on using the forward method of the java.servlet.RequestDispatcher interface

If you execute the forward method of the javax.servlet.RequestDispatcher class acquired with the getRequestDispatcher method of the javax.servlet.ServletRequest interface and javax.servlet.ServletContext interface, the following key attributes are added to the request object. However, the key attributes are not added in the forward method of the RequestDispatcher object acquired with the getNamedDispatcher method of the javax.servlet.ServletContext interface.

#1
This attribute is not added when the HTTP request received by the Web container does not contain the additional path information.

#2
This attribute is not added when the request URI of the HTTP request received by the Web container does not contain the query string.

These attributes are added by the Web container. The event of adding an attribute is not reported to javax.servlet.ServletRequestAttributeListener. For details on the values of the added attributes, see the Servlet 2.4 specifications.

(3) Deprecated javax.servlet.SingleThreadModel interface

The javax.servlet.SingleThreadModel interface is no longer recommended from the Servlet 2.4 specifications.

With the Application Server, you can use the javax.servlet.SingleThreadModel interface regardless of the Web application version. However, see the Servlet 2.4 specifications, note the reason for which this interface is deprecated, and then use the interface.

(4) setLocale method of the javax.servlet.ServletResponse interface

The character encoding is set in the Content-Type header of the HTTP response by the setLocale method of the javax.servlet.ServletResponse interface. In the Servlet 2.4 specifications, the conditions for enabling the set character encoding have been changed.

The conditions enabled in the Application Server is described separately for Servlet 2.4 and later versions and Servlet 2.3.

Servlet 2.4 and later versions
All the following conditions must be fulfilled:
  • The character encoding is set before the HTTP response is committed.
  • The character encoding is set before the getWriter method is invoked.
  • The character encoding is set before the setCharacterEncoding method is invoked.
  • The character encoding is not set by the setContentType method.
When the conditions are not fulfilled, the setLocal method does not set the character encoding of the response only by setting the locale in the ServletResponse class.

Servlet 2.3
The following condition must be fulfilled:
  • The character encoding is set before the HTTP response is committed#.

#
  • When the character encoding is set before the response is committed, the character encoding is set regardless of whether the setting is specified before or after the getWriter method is invoked.
  • When the character encoding is set before the response is committed, the character encoding is set regardless of whether the character encoding is set with the setContentType method.

(5) javax.servlet.UnavailableException

The javax.servlet.UnavailableException exception indicates that usage is permanently unavailable. The specifications of the HTTP response code when the servlets and JSPs that threw the javax.servlet.UnavailableException exception are accessed have been post scripted in the Servlet 2.4 specifications.

The HTTP response codes when the servlets and JSPs that threw the exception are accessed in the Application Server are described separately for Servlet 2.4 and later versions and Servlet 2.3.

Servlet 2.4 and later versions
404 error.

Servlet 2.3
503 error.

(6) sessionDestroyed method of the javax.servlet.http.HttpSessionListener interface

The timing for invoking the sessionDestroyed method of the javax.servlet.http.HttpSessionListener interface has been changed in the Servlet 2.4 specifications.

The timing when this method is invoked on the Application Server is described separately for Servlet 2.4 and later versions and Servlet 2.3.

Servlet 2.4 and later versions
The method is executed before the session is destroyed.

Servlet 2.3
The method is executed after the session is destroyed.

Note that when session timeout is disabled, the listener related to the session is reported in the following order. The order for each Web application version is as follows:

In Servlet 2.4 and later versions
  1. sessionDestroyed() method of the javax.servlet.http.HttpSessionListener interface
  2. valueUnbound() method of the javax.servlet.http.HttpSessionBindingListener interface
  3. attributeRemoved() method of the javax.servlet.http.HttpSessionAttributeListener interface

In Servlet 2.3
  1. valueUnbound() method of the javax.servlet.http.HttpSessionBindingListener interface
  2. attributeRemoved() method of the javax.servlet.http.HttpSessionAttributeListener interface
  3. sessionDestroyed() method of the javax.servlet.http.HttpSessionListener interface

(7) sendRedirect method of the javax.servlet.http.HttpServletResponse interface

The conditions for using the sendRedirect method of the javax.servlet.http.HttpServletResponse interface have been changed in the Servlet 2.4 specifications.

To execute this method on the Application Server normally, all the following conditions must be fulfilled:

The controlling of errors if these conditions are not fulfilled is described separately for Servlet 2.4 and later versions and Servlet 2.3.

Servlet 2.4 and later versions
If the conditions are not fulfilled, the java.lang.IllegalStateException exception is thrown.

Servlet 2.3
  • When the response is already committed
    The java.lang.IllegalStateException exception is thrown.
  • When an invalid URL is specified in the argument
    The response code is 404.

(8) Status message of HTTP status code 302

In the Servlet 2.4 specifications, SC_FOUND is added in the javax.servlet.http.HttpServletResponse interface as the constant indicating HTTP status code 302. Furthermore, for downward compatibility, SC_MOVED_TEMPORARILY defined in the Servlet 2.3 specifications can be used as it is.

On the Application Server, SC_FOUND and SC_MOVED_TEMPORARILY can be used regardless of any Web application version.

Note that the status message Found is used in the Web container in the following cases:

(9) HttpSession timeout during the execution of the service method of the servlet

In the Servlet 2.4 specifications, specifications are post scripted for the timeout in the javax.servlet.http.HttpSession interface during the execution of the service method.

On Application Server, regardless of the Web application version, the HttpSession does not timeout when the requests are being processed in the Web application.

Also, by controlling the number of concurrently executing threads in the Web applications or URL groups, the HttpSession does not timeout even when the request is pending. However, note that in the case of a pending request due to the controlling of the number of concurrently executing threads in the Web container, the HttpSession times out.

(10) Control when exception occurs in the listener

The description about the occurrence of an exception in the listener is added in the Servlet 2.4 specifications.

The control when an exception occurs in the listener if the Application Server is used is described separately for Servlet 2.4 and later versions and Servlet 2.3.

Servlet 2.4 and later versions
Even when there are multiple listeners for processing the relevant events, the listener after the one in which the exception occurred is not executed.

Servlet 2.3
The thrown exception is caught by the Web container. If multiple listeners are registered, the registered listeners are executed serially, as in normal cases, after the exception is caught.

(11) Commonly used external library (Extension)

The description about the handling of the MANIFEST file described when using the external library in the Web application has been changed in the Servlet 2.4 specifications.

On the Application Server, the existence of the MANIFEST file and the contents of the MANIFEST file are not checked regardless of the Web application version.

(12) Using the cross context between the Web applications with different servlet versions

The following table lists the operations after the requests using the cross context are forwarded and included between the Web applications with different servlet versions:

Table 6-21 Operations after forwarding and after including

Item No. Addition functionality of Servlet 2.4 specifications/ Functionality with differences in the Web application version Operations at the request forward destination/ include destination
forward/ include from 2.4 to 2.3#1 forward/ include from 2.3 to 2.4#2
1 Application of filters during forward and during include When you want to further implement forward or include from the servlets or JSPs after forward/ include is implemented, the Servlet 2.4 specifications are applied and you can use the filter. When you want to further implement forward or include from the servlets or JSPs after forward/ include is implemented, the Servlet 2.3 specifications are applied and you cannot use the filter.
2 Invocation of javax.servlet.ServletRequestAttributeListener The Servlet 2.4 specifications are applied and you can use the listener when you add attributes to the request. The Servlet 2.3 specifications are applied and you cannot use the listener when you add attributes to the request.
3 JSP compilation JSP compilation is executed as an application corresponding to Servlet 2.3. JSP compilation is executed as an application corresponding to Servlet 2.4.
4 setLocale method of the javax.servlet.ServletResponse interface The Servlet 2.4 specifications are applied and when all the following conditions are fulfilled, the settings for character encoding are enabled:
  • The character encoding is set before the response is committed.
  • The character encoding is set before the getWriter method is invoked.
  • The character encoding is set before the setCharacterEncoding method is invoked.
  • The character encoding is not set with the setContentType method.
The Servlet 2.3 specifications are applied and the settings for character encoding are applied if specified before the response is committed.
5 Dispatch to servlets and JSPs that throw the javax.servlet.UnavailableException indicating that the usage is permanently unavailable The Servlet 2.3 specifications are applied and a response with status 503 is returned. The Servlet 2.4 specifications are applied and a response with status 404 is returned.
6 sessionDestroyed method of the javax.servlet.http.HttpSessionListener interface The Servlet 2.4 specifications are applied and the method is executed before the HTTP session is destroyed. The Servlet 2.3 specifications are applied and the method is executed after the HTTP session is destroyed.
7 Specification of an invalid URL in the sendRedirect method of the javax.servlet.http.HttpServletResponse interface The Servlet 2.4 specifications are applied and the java.lang.IllegalStateException exception is thrown. The Servlet 2.3 specifications are applied and status 404 is set in the response.
8 Listener definition to be used In the case of the following listeners, the listener defined in the application at the forward or include destination will operate:
  • javax.servlet.ServletContextAttributeListener
In the case of the following listeners, the listener defined in the application that invokes the forward or include method will operate:
  • javax.servlet.ServletRequestAttributeListener
  • javax.servlet.http.HttpSessionListener
  • javax.servlet.http.HttpSessionAttributeListener
In the case of the following listeners, the listener defined in the application at the forward or include destination will operate:
  • javax.servlet.ServletContextAttributeListener
In the case of the following listeners, the listener defined in the application that invokes the forward or include method will operate:
  • javax.servlet.http.HttpSessionListener
  • javax.servlet.http.HttpSessionAttributeListener
9 Operations when an exception occurs in the listener in the application at the forward or include destination when multiple listeners are defined in web.xml for processing the relevant events In the case of the following listeners, the Servlet 2.4 specifications are applied and the listeners after the one in which an exception was thrown are not executed:
  • javax.servlet.ServletRequestAttributeListener
  • javax.servlet.http.HttpSessionListener
  • javax.servlet.http.HttpSessionAttributeListener
In the case of the following listeners, the Servlet 2.3 specifications are applied, the thrown exception is caught, and then the process moves to the next registered listener, as in normal operations:
  • javax.servlet.ServletContextAttributeListener
In the case of the following listeners, the Servlet 2.4 specifications are applied and the listeners after the one in which an exception was thrown are not executed:
  • javax.servlet.ServletContextAttributeListener
In the case of the following listeners, the Servlet 2.3 specifications are applied, the thrown exception is caught, and then the process moves to the next registered listener, as in normal operations:
  • javax.servlet.http.HttpSessionListener
  • javax.servlet.http.HttpSessionAttributeListener
10 Status code of response that displays the error page specified in web.xml The Servlet 2.4 specifications are applied and the response of the status code used when an error occurs is returned. The Servlet 2.3 specifications are applied and a response with status 200 is returned.

#1
Indicates the cases when forward or include is implemented from applications corresponding to Servlet 2.4 to applications corresponding to Servlet 2.3.

#2
Indicates the cases when forward or include is implemented from applications corresponding to Servlet 2.3 to applications corresponding to Servlet 2.4.

(13) When calling Session Bean of EJB 3.0 from the Web application of Servlet 2.4

When you call an EJB 3.0 Session Bean from a Servlet 2.4 Web application, do not specify the ejb-ref tag or ejb-local-ref. tag in web.xml. Instead, specify the @EJB annotation or @EJBs annotation in the servlet class.

The J2EE server executes DI of Enterprise Bean for the servlet.