Skip to Main Content

New to Java

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

How to use List<String> in JSP page?

843789Jan 2 2010 — edited Jan 3 2010
Hello All,

I am having problem using List<String> in my JSP page. Below is my JSP code.

<%@ page import="java.util.*, java.io.*"%>

<html>
<body>

<h1 align="center">Beer Recommendations JSP</h1>
<p>

<%
List<String> beerBrands = (List<String>)request.getAttribute("styles");
Iterator<String> it = beerBrands.iterator();
while(it.hasNext()){
out.print("<br>try: " + it.next());
}

%>

</body>
</html>

When I compile the above JSP code in Eclipse 3.4 (using JBoss 4.2 as my Application Server), I get the following Warning.

Type safety: Unchecked cast from Enumeration to Enumeration<String>

If I add the "@SuppressWarnings("unchecked")" to the code, Eclipse does not give any Error during compilation. But, at runtime, I get the following Error.


org.apache.jasper.JasperException: Unable to compile class for JSP:

An error occurred at line: 10 in the jsp file: /BeerAdvice.jsp
Syntax error, annotations are only available if source level is 5.0
7: <p>
8:
9: <%
10: @SuppressWarnings("unchecked")
11: List<String> beerBrands = (List<String>)request.getAttribute("styles");
12: Iterator<String> it = beerBrands.iterator();
13: while(it.hasNext()){


An error occurred at line: 11 in the jsp file: /BeerAdvice.jsp
The type List is not generic; it cannot be parameterized with arguments <String>
8:
9: <%
10: @SuppressWarnings("unchecked")
11: List<String> beerBrands = (List<String>)request.getAttribute("styles");
12: Iterator<String> it = beerBrands.iterator();
13: while(it.hasNext()){
14: out.print("<br>try: " + it.next());


An error occurred at line: 11 in the jsp file: /BeerAdvice.jsp
Syntax error, parameterized types are only available if source level is 5.0
8:
9: <%
10: @SuppressWarnings("unchecked")
11: List<String> beerBrands = (List<String>)request.getAttribute("styles");
12: Iterator<String> it = beerBrands.iterator();
13: while(it.hasNext()){
14: out.print("<br>try: " + it.next());


Any help is very much appreciated.

Thank you for your help.

Thanks,
Chubha
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Jan 31 2010
Added on Jan 2 2010
2 comments
2,247 views