InfoCenter Home >
3: Migration overview >
3.3: Migrating APIs and specifications >
3.3.3: Migrating to supported JSP specification >
3.3.3.2: Tips for migrating JSP .91 files to JSP 1.0
3.3.3.2: Tips for migrating JSP .91 files to JSP 1.0
Referring to WebSphere example code for the purposes of illustration,
the tips below cover some main steps in migrating JSP .91 to JSP 1.0.
Replacing <SERVLET> with <jsp:include>
Use the JSP 1.0 equivalent of <SERVLET> to include
data in a JSP page from another file.
Example |
CounterServletOutputPage.jsp |
JSP .91 |
<SERVLET CODE="WebSphereSamples.Counter.CounterServlet"></SERVLET>
|
JSP 1.0 |
<jsp:include page="/servlet/WebSphereSamples.Counter.CounterServlet" />
|
Discussion |
The CounterServletOutputPage.jsp file and the servlet it invokes are part of
the Version 3.5 Web application named WSsamples_app, with the Web Application
Web Path setting "/WebSphereSamples."
Using a WebSphere administrative client to view the WSsamples_app
Web application, you will find that it contains the Auto-Invoker servlet,
which enables you to call servlets by classname.
Specified within the Auto-Invoker servlet is the Servlet Web Path List,
which has the single entry "default_host/WebSphereSamples/servlet." Now,
the JSP and CounterServlet servlet are both under the Web
Application Web Path of /WebSphereSamples. Relative to /WebSphereSamples,
the servlet needs the additional qualifier of /servlet to properly locate it
(as specified in the Auto-Invoker). This results in the
"/servlet/WebSphereSamples.Counter.CounterServlet" in the <jsp:include>
tag.
|
Replacing <BEAN> with <jsp:useBean>
Use the JSP 1.0 equivalent of <BEAN> to make an
existing or newly created bean available from within the JSP file.
Four variations are possible.
Variation 1: JSP is to create the bean
Example |
PollServletInputPage.jsp |
JSP .91 |
<BEAN NAME="getQuestionDBBean"
TYPE="WebSphereSamples.Poll.GetQuestionDBBean"
CREATE="YES"
INTROSPECT="YES"
SCOPE="request">
</BEAN>
|
JSP 1.0 |
<jsp:useBean
id="getQuestionDBBean"
type="WebSphereSamples.Poll.GetQuestionDBBean"
class="WebSphereSamples.Poll.GetQuestionDBBean"
scope="request"/>
|
Discussion |
You no longer have the explicit attribute of CREATE="YES". Instead, if
the bean with the name specified by the id attribute is not found within
the specified scope, then an instance of bean will be created according
to the class attribute.
JSP NAME attribute corresponds to the JSP 1.0 id attribute. It is no
longer an INTROSPECT attribute. (The JSP .91 scope of requests and sessions
carry over to JSP 1.0, plus some new ones for JSP 1.0.) Compare with
variation 1 with variation 2.
|
Variation 2: JSP is to use existing bean
Example |
PollServletResultPage.jsp |
JSP .91 |
<BEAN
NAME="pollQueryDBBean"
TYPE="WebSphereSamples.Poll.PollQueryDBBean"
CREATE="NO"
INTROSPECT="NO"
SCOPE="request">
</BEAN>
|
JSP 1.0 |
<jsp:useBean
id="pollQueryDBBean"
type="WebSphereSamples.Poll.PollQueryDBBean"
scope="request"/>
|
Discussion |
Compare variation 2 with variation 1, which creates a bean if one does
not exist. JSP 1.0 version no longer has the class attribute from JSP .91.
If a bean instance corresponding to the id attribute not found in the
specified scope, there will be an error. As a result, the bean will not
be created.
|
Variation 3: Properties are to be set for bean
Example |
CenterGeneric.jsp |
JSP .91 |
<BEAN
NAME="getQuestionDBBean"
TYPE="WebSphereSamples.YourCo.Poll.GetQuestionDBBean"
CREATE="YES"
INTROSPECT="NO"
SCOPE="request">
<PARAM NAME="userID" VALUE="wsdemo">
</BEAN>
|
JSP 1.0 |
<jsp:useBean
id="getQuestionDBBean"
type="WebSphereSamples.YourCo.Poll.GetQuestionDBBean"
class="WebSphereSamples.YourCo.Poll.GetQuestionDBBean"
scope="request" />
<jsp:setProperty
name="getQuestionDBBean"
property="userID"
value="wsdemo" />
|
Discussion |
The example above has been shortened somewhat to set only one parameter.
Note that with JSP .91, the <PARAM> tag used within the <BEAN> tag.
In JSP 1.0, you must instead use the <jsp:setProperty> tag outside of
<jsp:useBean> tag.
You must properly link setting the property of an
existing bean by the name attribute within <jsp:setProperty> pointing to
the bean identified by the id attribute within <jsp:useBean>.
Similar considerations for <jsp:getProperty>.
|
Variation 4: Invoke methods on a bean
Example |
FeedbackServletResultPage.jsp |
JSP .91 |
<%
try {
java.lang.String _p0_1 = feedbackQuery.getWSDEMO_FEEDBACK_NAME(0);
%>
|
JSP 1.0 |
No change from JSP .91 to JSP 1.0 |
Discussion |
The NAME attribute in <BEAN> tag and id attribute in <jsp:useBean>
tag are equivalent. Both identify a bean named feedbackQuery. For either
JSP specification, invoking a method on a bean is identical.
|
Incorporating IBM extensions to JSP 1.0
See the Related information for references of IBM tags that extend JSP 1.0.
The tags might give you additional ideas for replacing JSP .91 tagging
functionality. In some cases, IBM extensions provide functionality that
was removed in the switch from JSP .91 to JSP 1.0. The remainder of this
article focuses on one such tag, <tsx:repeat>.
Replacing <REPEAT> with <tsx:repeat>
<tsx:repeat> provides for repeating information, which is
useful in creating HTML tables. <REPEAT> from JSP .91 is usually
used with <INSERT> to actually insert data from
specified bean. <REPEAT> from JSP .91 does not have an equivalent
in the JSP 1.0 specification. However, the IBM extension <tsx:repeat>
provides much the same function.
Example |
timeout.jsp (available in Advanced Ediiton only) |
JSP .91 |
<REPEAT INDEX="i">
<%timeoutBean.getBalance(i);%>
<TD><INSERT BEAN="timeoutBean" PROPERTY="balance"></INSERT></TD>
</REPEAT>
|
JSP 1.0 |
<txt:repeat index="i">
<TD> <%= timeoutBean.getBalance(i) %> </TD>
</txt:repeat>
|
Discussion |
Note that there is an actual call, using Java syntax, of getBalance
method of timeoutBean, within loop of <tsx:repeat>, rather than use of
IBM JSP 1.0 extension <tsx:getProperty>. This is because getBalance
method requires an explicit argument to specify which row of data from
underlying array in timeoutBean is to be returned. Thus, <tsx:getProperty>
not suitable.
|
|
|