This week's book giveaway is in the Other Languages forum.
We're giving away four copies of Functional Reactive Programming and have Stephen Blackheath and Anthony Jones on-line!
See this thread for details.
Win a copy of Functional Reactive Programming this week in the Other Languages forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Scriptlets

 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Oliver Rensen
Ranch Hand
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 20667
65
Chrome Eclipse IDE Java Windows
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 109
Eclipse IDE Firefox Browser Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic