aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes Scriptlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "Scriptlets" Watch "Scriptlets" New topic
Author

Scriptlets

Oliver Rensen
Ranch Hand

Joined: Jul 23, 2004
Posts: 109

When I want to use generics within scriptlets, how do I must mask the brackets < and > ?

& l t ; and & g t ; does not work.
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

Scriptlets inside a JSP page can contain anything that does not close the scriptlet; comparison operators and generics should pose no problem.

In a JSP document &lt; and &gt; should work just fine, but if it fails you can enclose the entire code in <![CDATA[ and ]]>:


If this still fails, make sure that your web container supports Java 5.0 or up. If it doesn't then of course you can't use generics.


SCJP 1.4 - SCJP 6 - SCWCD 5 - OCEEJBD 6
How To Ask Questions How To Answer Questions
Oliver Rensen
Ranch Hand

Joined: Jul 23, 2004
Posts: 109

Thank you Rob, but how do I must combine the CDATA-tag with the scriptlet-tag?

The following examples do not work:

<% <![CDATA[
List<Integer> genericsWithinJSP = new ArrayList<Integer>();
genericsWithinJSP.add(1);
]]> %>

<jsp:scriptlet> <![CDATA[
List><Integer> genericsWithinJSP = new ArrayList<Integer>();
genericsWithinJSP.add(1);
]]> </jsp:scriptlet>

<![CDATA[ ><jsp:scriptlet>
List<Integer> genericsWithinJSP = new ArrayList<Integer>();
genericsWithinJSP.add(1);
</jsp:scriptlet> ]]>
Rob Spoor
Sheriff

Joined: Oct 27, 2005
Posts: 19538
    
  16

Oliver Rensen wrote:<jsp:scriptlet> <![CDATA[
List><Integer> genericsWithinJSP = new ArrayList<Integer>();
genericsWithinJSP.add(1);
]]> </jsp:scriptlet>

That one should work, provided it is a JSP (XML) document.

If you use the first form you don't need to use CDATA:

If this still fails, there are two things you should check:
1) did you import List and ArrayList?
2) does a scriptlet with only autoboxing work?

If autoboxing does not work it's very likely that your servlet container simply does not support Java 5.0 and higher.
Oliver Rensen
Ranch Hand

Joined: Jul 23, 2004
Posts: 109

Rob, you are right. My web-container does not support Java 5.
I'm using JBoss 4.0.2, and even though I have startet JBoss with Java 5, and even though I'm using generics in my DAO (and this works), I cannot use generics or autoboxing in my JSP. The following scriptlet-code fails:

int i1 = 5;
Integer i2 = i1;
int i3 = i2;

It seems, I should update my application-server to a higher version.

Thank you very much.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Scriptlets
 
Similar Threads
JSP Doubt?
Custom tags
Scriptlets with icefaces
Strange Behavior of JSP
Can't include other page content with RequestDispatcher.include()