A friendly place for programming greenhorns!
Big Moose Saloon
Search
|
Java FAQ
|
Recent Topics
Register / Login
JavaRanch
»
Java Forums
»
Java
»
JSP
Author
forEach giving error
Vibhas Kumar
Greenhorn
Joined: Oct 13, 2009
Posts: 28
posted
Feb 07, 2010 03:55:08
0
Hi All i am facing a problem while using the forEach for iteration i am giving the complete code please tell me whats wrong with this.
index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1"> <title>Insert title here</title> </head> <body> <form method="get" action="go"> <center><input type="SUBMIT"></center> </body> </html>
web.xml
<?xml version="1.0" encoding="UTF-8"?> <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5"> <display-name>FirstJsp</display-name> <context-param> <param-name>javax.faces.STATE_SAVING_METHOD</param-name> <param-value>client</param-value> </context-param> <listener> <listener-class>com.sun.faces.config.ConfigureListener</listener-class> </listener> <servlet> <servlet-name>faces</servlet-name> <servlet-class>javax.faces.webapp.FacesServlet</servlet-class> <load-on-startup>1</load-on-startup> </servlet> <servlet-mapping> <servlet-name>faces</servlet-name> <url-pattern>*.jsf</url-pattern> </servlet-mapping> <servlet-mapping> <servlet-name>faces</servlet-name> <url-pattern>*.faces</url-pattern> </servlet-mapping> <servlet> <description></description> <display-name>foreachservlet</display-name> <servlet-name>foreachservlet</servlet-name> <servlet-class>com.foreach.foreachservlet</servlet-class> </servlet> <servlet-mapping> <servlet-name>foreachservlet</servlet-name> <url-pattern>/go</url-pattern> </servlet-mapping> <welcome-file-list> <welcome-file>index.html</welcome-file> <welcome-file>index.htm</welcome-file> <welcome-file>index.jsp</welcome-file> <welcome-file>default.html</welcome-file> <welcome-file>default.htm</welcome-file> <welcome-file>default.jsp</welcome-file> </welcome-file-list> <context-param> <param-name>javax.servlet.jsp.jstl.fmt.localizationContext</param-name> <param-value>resources.application</param-value> </context-param> </web-app>
Servlet
code:
package com.foreach; import java.io.IOException; import javax.servlet.RequestDispatcher; import javax.servlet.ServletException; import javax.servlet.http.HttpServlet; import javax.servlet.http.HttpServletRequest; import javax.servlet.http.HttpServletResponse; public class foreachservlet extends HttpServlet { private static final long serialVersionUID = 1L; public foreachservlet() { super(); } protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { try{ System.out.println("Getting inside get method--"); String[] movieList={"Isquia","3 idiots","Kurbaan","Jab we met"}; request.setAttribute("movieList",movieList); System.out.println("After setting attribute"); RequestDispatcher dispatcher=request.getRequestDispatcher("/pages/welcome.jsp"); dispatcher.forward(request, response); System.out.println("Last line--"); }catch(Exception e){ e.printStackTrace(); } } }
jsp code:
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN"> <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %> <HTML> <HEAD><TITLE>Movie Collections</TITLE></HEAD> <BODY> <strong>Movie list</strong><br></br> <TABLE BORDER=5 ALIGN="CENTER"> <c:forEach var="movie" items="${movieList}"> <tr> <td>${movie}</td> </tr> </c:forEach> </TABLE> </BODY> </HTML>
I am getting the following error i am unable to understand .
welcome.jsp:9:24: Static attribute must be a String literal, its illegal to specify an expression. <c:forEach var="movie" items="${movieList}"> ^---^ welcome.jsp:9:24: Static attribute must be a String literal, its illegal to specify an expression. <c:forEach var="movie" items="${movieList}"> ^---^
Please help. Thanks
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Feb 07, 2010 07:43:18
0
I edited your post to make it easier to understand.
Try using
http://java.sun.com/jsp/jstl/core
as the taglib URI.
Bear Bibeault
Author and ninkuma
Marshal
Joined: Jan 10, 2002
Posts: 56157
13
I like...
posted
Feb 07, 2010 10:53:05
0
This is all covered in the
JSP
FAQ.
[
Smart Questions
] [
JSP FAQ
] [
Books by Bear
] [
Bear's FrontMan
] [
About Bear
]
David Newton
Author
Rancher
Joined: Sep 29, 2008
Posts: 12617
I like...
posted
Feb 07, 2010 11:26:46
0
(Why is this the error message produced? Now *I'm* being the lazy one ;)
I agree. Here's the link:
http://aspose.com/file-tools
subject: forEach giving error
Similar Threads
When trying to deploy my JSF 2.0 JSP page I get this:
ContextListener Problem
JSF Spring integration
Calendar in jsf
jsf problem , java.lang.RuntimeException: Cannot find FacesContext error
All times are in JavaRanch time: GMT-6 in summer, GMT-7 in winter