aspose file tools*
The moose likes JSP and the fly likes Generics in scriptlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Generics in scriptlets" Watch "Generics in scriptlets" New topic
Author

Generics in scriptlets

Oliver Rensen
Ranch Hand

Joined: Jul 23, 2004
Posts: 109

Hello ranchers,

this does not work in a scriptlet in a JSP:

<%
SortedMap<String, Integer> map = new TreeMap<String, Integer>();
%>

An error occurred at line: 36 in the jsp file: /WEB-INF/prodList.jsp
Generated servlet error:
Syntax error on token "<", ( expected

An error occurred at line: 36 in the jsp file: /WEB-INF/prodList.jsp
Generated servlet error:
Syntax error, insert ")" to complete Expression

An error occurred at line: 36 in the jsp file: /WEB-INF/prodList.jsp
Generated servlet error:
Syntax error on token "<", ( expected

An error occurred at line: 36 in the jsp file: /WEB-INF/prodList.jsp
Generated servlet error:
Syntax error on token "(", invalid Expression


This does not work, too:

<%
SortedMap & l t ; String, Integer & g t ; map = new TreeMap & l t ; String, Integer & g t ; ();
%>

The blanks between & l t ; and & g t ; are only to display the code in this thread.
In my JSP there are no blanks.

An error occurred at line: 36 in the jsp file: /WEB-INF/prodList.jsp
Generated servlet error:
Syntax error on token "&", invalid AssignmentOperator

An error occurred at line: 36 in the jsp file: /WEB-INF/prodList.jsp
Generated servlet error:
Syntax error on token ",", invalid AssignmentOperator

An error occurred at line: 36 in the jsp file: /WEB-INF/prodList.jsp
Generated servlet error:
Syntax error on token "new", delete this token

An error occurred at line: 36 in the jsp file: /WEB-INF/prodList.jsp
Generated servlet error:
Syntax error on token ",", invalid AssignmentOperator

An error occurred at line: 36 in the jsp file: /WEB-INF/prodList.jsp
Generated servlet error:
Syntax error on token ";", this expected after this token


How can I work with generics in scriptlets?


Regards,
Oliver
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
Just donĀ“t use scriptlets at all. Java code belongs in Java classes, not in JSP files. Make use of servlets, beans, DAO and/or utility classes.

To control output and flow in JSP, just use taglibs (JSTL, JSF, etc) and EL the usual way.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Generics in scriptlets