uCosminexus Application Server, Web Container Functionality Guide

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

6.2.6 Precautions for implementing JSPs

This subsection describes the precautions for implementing JSPs.

Organization of this subsection
(1) Notes for using the include directive
(2) Notes for using the tag library
(3) Notes for coding the <%=%> tag
(4) Access based on URL specification and mapping definition
(5) Notes for using the <jsp:plugin> tag
(6) Version attributes in the JSP document
(7) Mapping of URI and TLD files specified in the uri attribute of the taglib directive
(8) Notes for including a dynamic page in JSP
(9) Coding the internal subset to the DOCTYPE declaration in the TLD file
(10) Specifying the external subset URI in the JSP document and XML tag file
(11) Values of the javax.servlet.jsp.jspException attribute of the javax.servlet.ServletRequest object
(12) Precautions related to the TLD file version
(13) Character encoding supported in JSP
(14) Notes on using the setProperty action
(15) Specifying a null character string in an attribute of a JSP tag
(16) Precautions related to coding the scriptlet before and after the template text of JSP
(17) Precautions related to using the scriptlet
(18) Translation error when the EL is disabled
(19) Coding schemaLocation in the TLD file

(1) Notes for using the include directive

(2) Notes for using the tag library

(3) Notes for coding the <%=%> tag

When using the <%= %> tag in JSP, make sure that you do not include a semicolon (;) in the tag. If the semicolon is entered, an error occurs during JSP compilation.

(4) Access based on URL specification and mapping definition

When you access the JSP file path directly by specifying the URL and when you access the path using a URL with the mapping defined, separate instances are generated in each case. Therefore, note that the jspInit method is executed in each instance. If the specification in the in the <load-on-startup> tag is to load the instance during startup, the instance loaded during startup is same as the one that is accessed using the URL with the mapping defined.

(5) Notes for using the <jsp:plugin> tag

Make sure that you specify the plugin action or the code attribute of the <jsp:plugin> tag in the JSP document on the JSP page. If omitted, a compilation error occurs.

(6) Version attributes in the JSP document

In the JSP document, describe the information about the version used as the attribute of the <jsp:root> tag. However, the scope of functionality available in JSP is in accordance with the version information of web.xml of the Web application containing the relevant JSP.

For example, even if the JSP document describes <jsp:root version="1.2">, you can use JSP EL added in the JSP 2.0 specifications.

(7) Mapping of URI and TLD files specified in the uri attribute of the taglib directive

The URI specified in the uri attribute of the taglib directive is mapped using one of the following methods as per the JSP specifications. You cannot map the same URI to a different TLD file. If the URI is duplicated, the following numbering is considered as the priority order and the mapping with a higher priority order is enabled:

  1. Implicit mapping of JSTL and JSF URI (Web application of Servlet 2.5 or later specifications)
  2. Mapping of URI specified in the <taglib-uri> element of the <taglib> element in web.xml with the TLD file specified in the <taglib-location> element
  3. Mapping of the URI specified in the <uri> element of the TLD file in the Web application with the same TLD file
  4. Mapping of the URI specified in the <uri> element of the TLD file stored under the /META-INF directory of the library JAR (in the case of the cjjspc command, the JAR file specified in the -classpath option) with the same TLD file

The examples of description of directory structures and files used when the URI and TLD files are mapped as specified from step 2 to 4 are as follows:

(a) Mapping of the URI specified in the <taglib-uri> element of the <taglib> element in web.xml and the TLD file specified in the <taglib-location> element (in 2.)

An example of description of the directory structure and files in the case of point 2 is as follows:

In the case of point 2, the TLD file is stored in the Web application. The example of the directory structure in point 2 is as follows:

Figure 6-3 Directory structure (in the case of point 2.)

[Figure]

The following figure shows the mapping of the URI specified in the uri attribute of the taglib directive and the TLD file for this directory structure.

Figure 6-4 Mapping of the URI and TLD file (in the case of point 2.)

[Figure]

The correspondence of data in the figure is explained below:

  1. The prefix specified in the taglib directive is specified in the tag prefix.
  2. The value specified in the <name> element of the TLD file is associated with the JSP file prefix.
  3. The uri specified in the taglib directive of the JSP file is specified in the <taglib-uri> element of web.xml.
  4. The name of the TLD file to be mapped is specified in the <taglib-location> element of web.xml.
(b) When mapping the URI specified in the <uri> element of the TLD file and the same TLD file

An example of description of the directory structure and files in the case of points 3 or 4 is described here.

In the case of point 3, the TLD file is stored in the Web application. The example of the directory structure in point 3 is as follows:

Figure 6-5 Directory structure (in the case of point 3)

[Figure]

In the case of point 4, the TLD file is stored under the /META-INF directory of library JAR. The example of the directory structure in point 4 is as follows:

Figure 6-6 Directory structure (in the case of point 4)

[Figure]

The following figure shows the mapping of the URI specified in the uri attribute of the taglib directive and the TLD file in the directory structure for the points 3 or 4:

Figure 6-7 Mapping of the URI specified in the <uri> element of the TLD file and the same TLD file (in the case of points 3 or 4)

[Figure]

The correspondence of data in the figure is explained below:

  1. The prefix specified in the taglib directive is specified in the tag prefix.
  2. The value specified in the <name> element of the TLD file is associated with the JSP file prefix.
  3. The uri specified in the taglib directive of the JSP file is specified in the <url> element of TLD file.

If a duplicate URI is detected, the following messages are output for the Web applications and the relevant mapping is ignored:

Table 6-22 Messages output and the output conditions in the case of URI duplication

Message ID Output conditions
KDJE39314-W

In the case of the J2EE server mode, servlet engine mode, or cjjspc command
This message is output when the contents of the <uri> element described in the TLD files are duplicated with the contents of the <taglib-uri> element in web.xml or the contents of the <uri> element described in another TLD file.

In the case of the cjjsp2java command
This message is output when the contents of the <uri> element described in the TLD file are duplicated with the uri contents specified in the command argument -taglib or the contents of the <uri> element described in another TLD file.
KDJE39315-W This message is output when the contents of the <uri> element described in the TLD file are duplicated with the contents of the <uri> element described in another TLD file.
KDJE39316-W This message is output when another <taglib> element is specified containing the <taglib-uri> element that duplicates with the contents of <taglib> element specified in web.xml.
KDJE39325-W This message is output when the contents of the <taglib-uri> element of web.xml or the contents of the <uri> element described in another TLD file is duplicated with the URI of the tag library (JSTL, and JSF) in the Java EE specifications.
KDJE39326-W This is message is output when the contents of the <uri> element of the TLD file stored in the library JAR (in the case of the cjjspc command, JAR file specified in the -classpath option) are duplicated with the contents of the <taglib-uri> element of web.xml or the contents of the <uri> element described in another TLD file.

(8) Notes for including a dynamic page in JSP

To include dynamic pages such as JSPs and servlets in JSP, use the include action instead of the include method of javax.servlet.RequestDispatcher.

(9) Coding the internal subset to the DOCTYPE declaration in the TLD file

Do not code the internal subset for the DOCTYPE declaration in the TLD file (tag library descriptor).

You can only specify absolute URI as the URI specified in the xsi:schemaLocation attribute with the tag element extension or the element extension of the tag library. Do not reference definitions other than DTD/ XML schema defined in the Java EE specifications with purposes other than tag element extension or the element extension of the tag library.

(10) Specifying the external subset URI in the JSP document and XML tag file

When you specify the DOCTYPE declaration, you can only specify the absolute URI as the external subset URI. Also, when you reference the external entity defined in the XML1.0 specifications, you can only specify the absolute URI as the URI specified in the external entity declaration. You cannot reference the external subset and external entity with the relative URI specified.

(11) Values of the javax.servlet.jsp.jspException attribute of the javax.servlet.ServletRequest object

When an exception is thrown in the JSP file and if the error page is specified in the errorPage attribute of the page directive, the exception is described in the JSP specifications if the error page is set in the javax.servlet.jsp.jspException attribute of the javax.servlet.ServletRequest object, but the exception is also set when the error page is specified in the errorPage attribute of the page directive.

(12) Precautions related to the TLD file version

In 07-00 or later versions, the version of the TLD file (JSP version to which the TLD file corresponds) is checked during JSP translation. Therefore, if the TLD file version is a JSP of a level higher than the version of JSP and TLD file corresponding to the Web application version, an error occurs in JSP translation. Also, in JSP 1.2 and in JSP 2.0 or later specifications, the schema language must be defined in the TLD file.

The TLD file version is determined from the schema language described in the TLD file. However, if the schema language is not defined, the TLD file version is determined from the Web application version.

The following table lists the versions of TLD file when the schema language is not defined in the TLD file:

Table 6-23 TLD file version when the schema language is not defined

Version of the Web application TLD file version
2.2 1.1
2.3 1.2
2.4 2.0
2.5 2.1

(13) Character encoding supported in JSP

This point describes the character encoding that can be used in the JSP file and tag file.

(a) In the case of the JSP page

The character encoding that can be used on the JSP page and the specification method of character encoding is described below:

(b) In the case of the JSP document (in the case of the Web applications compliant with Servlet 2.4 or later specifications)

The character encoding that can be used in the JSP documents in the Web application compliant with the Servlet 2.4 or later specifications and the specification method of the character encoding to be used is described below:

Note
For the character encoding supported by the Cosminexus XML Processor, see 1.3.2 Character codes that can be processed in the uCosminexus Application Server XML Processor User Guide.
(c) In the case of the JSP document (in the case of the Web applications compliant with Servlet 2.3 specifications)

The character encoding that can be used in the JSP documents in the Web application compliant with the Servlet 2.3 specifications and the specification method of the character encoding to be used is as follows:

(d) In the case of the tag file with standard syntax

The character encoding that can be used in the tag file with the standard syntax and the specification method of the character encoding to be used is described below:

(e) In the case of the tag file with XML syntax

The character encoding that can be used in the tag file with the XML syntax and the specification method of the character encoding to be used is described below:

Note:
For the character encoding supported by the Cosminexus XML Processor, see 1.3.2 Character codes that can be processed in the uCosminexus Application Server XML Processor User Guide.
(f) Default character encoding

If the character encoding is not explicitly specified in the JSP file or tag file, the JSP is processed using the default character encoding.

Note that even in this case, make sure that the default character encoding matches with the character encoding used in the tag file. The following table lists the default character encoding for the Servlet and JSP specifications:

Table 6-24 Default character encoding

Specifications JSP page JSP document Tag file with standard syntax Tag file with XML syntax
Servlet 2.2/ JSP1.1 ISO-8859-1 ISO-8859-1 -- --
Servlet 2.3/ JSP 1.2 ISO-8859-1 ISO-8859-1 -- --
Servlet 2.4 or later/ JSP 2.0, JSP 2.1 ISO-8859-1 UTF-8 ISO-8859-1 UTF-8

Legend:
--: Not applicable

You can also set the default character encoding by using the setup functionality for default character encoding. For details, see 2.6 Functionality for setting up the default character encoding.

(14) Notes on using the setProperty action

Do not specify an invalid value in the setProperty action in the JSP page or in the name attribute of the jsp:setProperty tag in the JSP document. Operation is not guaranteed if you specify an invalid value in the name attribute of the jsp:setProperty tag.

(15) Specifying a null character string in an attribute of a JSP tag

Do not specify a null character string in an attribute of a directive or action tag in a JSP page or in a tag that begins with "jsp:" in a JSP document.

(16) Precautions related to coding the scriptlet before and after the template text of JSP

When you want to code a scriptlet that includes a control character such as an if statement before and after the template text of JSP, you must enclose the scriptlet explicitly in "{}" (curly brackets).

As a result of the JSP compilation, a one-lined JSP template text does not necessarily become a one lined statement in the Java file. It is sometimes output as a multi-lined statement. Therefore, if you do not code a scriptlet that includes a control character such as an if statement before and after the template text of JSP, by enclosing it explicitly in the "{}" (curly brackets), unintended operations might occur.

(17) Precautions related to using the scriptlet

When you code the Java code in a JSP by using a scriptlet and you want to code the return statement or throw statement in the scriptlet, code within a block such as an if statement.

(18) Translation error when the EL is disabled

If the JSP includes a character string such as ${aaa, which is incorrect as an EL, an invalid EL translation error occurs even when you set the EL to a disabled status.

The following table lists the EL starting characters for which the translation error occurs for each version of the JSP specifications.

Table 6-25 TableEL starting character for which the translation error occurs

Version of the JSP specifications EL starting character
JSP2.1 '$', '#'
JSP2.0 '$'
JSP1.2 None

(19) Coding schemaLocation in the TLD file

For schemaLocation coded in the TLD file, you must specify either of the values given in the following table, depending on the version of TLD.

Version of TLD Value to be specified in schemaLocation
2.0 "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-jsptaglibrary_2_0.xsd"
2.1 "http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-jsptaglibrary_2_1.xsd"