uCosminexus Application Server, Web Container Functionality Guide

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

2.3.6 Checking the duplication of the id attribute of the <jsp:useBean> tag

If the id attribute value of the <jsp:useBean> tag is duplicated in the JSP specifications, a translation error occurs and the JSP compilation fails.

With Application Server, you can compile JSP by controlling the occurrence of translation errors because of the duplication of the id attribute value of the <jsp:useBean> tag.

If you control the occurrence of translation errors because of the duplication of the id attribute value of the <jsp:useBean> tag, the JSPs will run without any problem even if the id attribute value of the <jsp:useBean> tag is duplicated. The following JSP file coding example describes this case:

Example for coding a JSP file

(Omitted)
...
<% if (Conditional-expression) { %>
<jsp:useBean id="BeanTest" class="test.TestClass1" />
<% } else { %>
<jsp:useBean id="BeanTest" class="test.TestClass2" />
<% } %>
...
(Omitted)

By using the scriptlet and coding the <jsp:useBean> tag in the if clause and the else clause respectively, only one <jsp:useBean> tag is executed. Therefore, even if the id attribute value of the <jsp:useBean> tag is duplicated, JSP will operate without a problem.


When you control the occurrence of translation errors because of duplication of the id attribute value of the <jsp:useBean> tag, the KDJE39544-I message is output when the id attribute value of the <jsp:useBean> tag is duplicated.

Organization of this subsection
(1) How to enable the id attribute duplication check of the <jsp:useBean> tag
(2) Notes

(1) How to enable the id attribute duplication check of the <jsp:useBean> tag

To control the occurrence of translation errors because of the duplication of the id attribute value of the <jsp:useBean> tag, use one of the following methods:

(2) Notes

The JavaBeans object created in the <jsp:useBean> tag is managed within the scope that is specified in the scope attribute using the id attribute value as the key. Therefore, when the following conditions are fulfilled, the unintended JavaBeans objects might be acquired and the invalid operations might be performed:

The following points describe the examples for coding JSP files in which the intended objects might not be acquired, when controlling the occurrence of a translation error because of the duplication of the id attribute value in the <jsp:useBean> tag.

(a) Coding example of JSP file when an unintended JavaBeans object is acquired with a single request (Example in which the same id attribute is specified in two or more different conditional expressions)
(Omitted)
...
<% if (Conditional-expression-1) { %>
<jsp: useBean id="BeanTest" class="test.TestClass1" scope="page"/>
<% } %>
<% if (Conditional-expression-1) { %>
<jsp: useBean id="BeanTest" class="test.TestClass2" type="test.TestIF" scope="page"/>
<% } %>
...
(Omitted)

The same id attribute value (BeanTest) is specified in the conditional expression 1 and the conditional expression 2. If the conditions in both conditional expression 1 and conditional expression 2 are fulfilled, the test.TestClass1 class object is acquired in the first <jsp:useBean> tag and the second <jsp:useBean> tag, and the test.TestClass2 class object is not acquired.

The test.TestClass1 class object is registered for the id attribute value 'BeanTest' in the first <jsp:useBean> tag. As per the interpretation, the processing for the id attribute value 'BeanTest' is the same as that of the second <jsp:useBean> tag, and therefore, the test.TestClass1 class object that is already registered in the first <jsp:useBean> tag will be acquired.

(b) Coding example of JSP file when unintended JavaBeans objects are acquired with multiple requests (Example in which the same id attribute value is specified in if and else statements)
(Omitted)
...
<% if (Conditional-expression) { %>
<jsp: useBean id="BeanTest" class="test.TestClass1" scope="session"/>
<% } else { %>
<jsp: useBean id="BeanTest" class="test.TestClass2" scope="session"/>
<% } %>
...
(Omitted)

The same id attribute value (BeanTest) is specified in if and else statements. If a request is received twice and the conditional expression of the if statement is established in the first request and the conditional expression of the if statement is not established in the second request, the test.TestClass1 class object is acquired in both the first <jsp:useBean> tag and the second <jsp:useBean> tag, and the test.TestClass2 class object is not acquired.

The test.TestClass1 class object is registered for the id attribute value 'BeanTest' in the first <jsp:useBean> tag. As per the interpretation, the processing for the id attribute value 'BeanTest' is the same as that of the second <jsp:useBean> tag, and therefore, the test.TestClass1 class object that is already registered in the first <jsp:useBean> tag will be acquired.

(c) Coding example 2 of JSP file when unintended JavaBeans objects are acquired with multiple requests (Example 1 of invoking JavaBeans object by using the id attribute value, commonly specified in 2 or more <jsp:useBean> tags, in <jsp:getProperty> tag or <jsp:setProperty> tag)
(Omitted)
...
<% if (Conditional-expression-1) { %>
<jsp:useBean id="BeanTest" class="test.TestClass1" scope="page"/>
<% } %>
<% if (Conditional-expression-2) { %>
<jsp:useBean id="BeanTest" class="test.TestClass2" type=" test.TestIF" scope="page"/>
<% } %>
...
<jsp:setProperty name="BeanTest" property="*"/>
...
<jsp: getProperty name="BeanTest" property="value"/>
...
(Omitted)

The JavaBeans object created in the <jsp:useBean> tag will be invoked with the processes defined in the <jsp:getProperty> and the <jsp:setProperty> tag.

If the id attribute value is duplicated in 2 or more <jsp:useBean> tags that create different JavaBeans classes, the object specified in the <jsp:useBean> tag that appears at the end is used for the processing in the <jsp:getProperty> or <jsp:setProperty> tags.

For example, the same id attribute value (BeanTest) is specified in the conditional expression 1 and conditional expression 2. Therefore, even if the conditional expression 1 is established, the test.TestClass1 class object registered in first <jsp:useBean> tag is not used for the processing in the <jsp:getProperty> and <jsp:setProperty> tags.

(d) Coding example 3 of JSP file when unintended JavaBeans objects are acquired with multiple requests (Example 2 of invoking JavaBeans object by using the id attribute value, commonly specified in 2 or more <jsp:useBean> tags, in <jsp:getProperty> tag or <jsp:setProperty> tag)
(Omitted)
...
<% if (Conditional-expression-1) { %>
<jsp: useBean id="BeanTest" class="test.TestClass1" scope="page"/>
...
<jsp: setProperty name="BeanTest" property="*"/>
...
<jsp: getProperty name="BeanTest" property="value"/>
...
<% } %>
<% if (Conditional-expression-2) { %>
<jsp: useBean id="BeanTest" class="test.TestClass2" type=" test.TestIF" scope="page"/>
...
<jsp: setProperty name="BeanTest" property="*"/>
...
<jsp: getProperty name="BeanTest" property="value"/>
...
<% } %>
...
(Omitted)

The JavaBeans object created in the <jsp:useBean> tag will be invoked in the processes defined in the <jsp:getProperty> tag and the <jsp:setProperty> tag.

If the id attribute value is duplicated in two or more <jsp:useBean> tags that create different JavaBeans classes, the object specified in the <jsp:useBean> tag that is displayed at the end is used for the processing in the <jsp:getProperty> tag or the <jsp:setProperty> tag.

For example, the same id attribute value (BeanTest) is specified in the conditional expression 1 and conditional expression 2. Therefore, even if the conditional expression 1 is established, the test.TestClass2 class object registered in the second <jsp:useBean> tag is used for the processing in the first <jsp:useBean> tag. The test.TestClass1 class object registered in the first <jsp:useBean> tag is not used for the processing in the <jsp:getProperty> tag and the <jsp:setProperty> tag.