• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Generics in scriptlets

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