Help putting a scriplet in a jsp

I have the following jsp page which i have created a scriplet inside which should go around the arraylist and pull the data into a table but i am getting a error message when trying this the jsp is:

<BODY BGCOLOR>

<jsp:usebean id="pricePassed"

class ="MySite.displayBean"

Scope="request"/>

<center><img src="image.jpg" width="350" height="200" /> </center>

<h1>The price ranged is </h1>

<h2><font color="white"><B><U> <jsp:getProperty name="pricePassed" property="pricePassed" /> </U></B></font></h2>

<P>

<center><a href="http://localhost:8080/examples/home.html

">Back</a></center>

<% = Iterator it = collection.iterator();

while( it.hasNext() ){

videoBean vids = (videoBean) it.next();

out.println("<TR>" +

"<TD>" + vids.getTitle() +"</TD>" +

"<TD>" + vids.getDirector() +"</TD>" +

"<TD>" + vids.getRating() +"</TD>" +

"<TD>" + vids.getYearReleased() +"</TD>" +

"<TD>" + vids.getPrice() +"</TD>" +

"<TD>" + vids.getStockCount() +"</TD>" +

"<TD>" + vids.getImageName() +"</TD></TR>\n" );

} %>

</body>

</html>

The error says:

org.apache.jasper.JasperException: Unable to compileclassfor JSPNote: sun.tools.javac.Main has been deprecated.

An error occurred between lines: 9 and 16 in the jsp file: /display.jsp

[2477 byte] By [eastendersa] at [2007-11-27 1:14:06]
# 1
I've no idea if this is causing the error you're reporting, but yank that "=" from the line <% = Iterator it = collection.iterator();
tsitha at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 2

thanks not sure it this is better or worse lol but now i get :

org.apache.jasper.JasperException: Unable to compile class for JSPNote: sun.tools.javac.Main has been deprecated.

An error occurred between lines: 16 and 27 in the jsp file: /display.jsp

Generated servlet error:

D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\examples\display$jsp.java:65: Class org.apache.jsp.Iterator not found.

Iterator it = collection.iterator();

^

An error occurred between lines: 16 and 27 in the jsp file: /display.jsp

Generated servlet error:

D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\examples\display$jsp.java:65: Undefined variable or class name: collection

Iterator it = collection.iterator();

^

An error occurred between lines: 16 and 27 in the jsp file: /display.jsp

Generated servlet error:

D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\examples\display$jsp.java:67: Class org.apache.jsp.videoBean not found.

videoBean vids = (videoBean) it.next();

^

An error occurred between lines: 16 and 27 in the jsp file: /display.jsp

Generated servlet error:

D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\examples\display$jsp.java:67: Class org.apache.jsp.videoBean not found.

videoBean vids = (videoBean) it.next();

^

4 errors, 1 warning

eastendersa at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 3
is there any way of inporting in a jsp? could it be that i need to import the package for list or iteration? Anybody have any ideas?
eastendersa at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 4
<%@ page import="java.util.*, java.math.*" %>
hunter9000a at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 5
But you shouldn't be using scriptlets. If you want an iterator for a for loop or something, then check out the JSTL foreach Tag.
masijade.a at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 6

thank you i put that in it got rid of the first error now i am just left with:

Generated servlet error:

D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\examples\display$jsp.java:65: Undefined variable or class name: collection

Iterator it = collection.iterator();

^

An error occurred between lines: 16 and 27 in the jsp file: /display.jsp

Generated servlet error:

D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\examples\display$jsp.java:67: Class org.apache.jsp.videoBean not found.

videoBean vids = (videoBean) it.next();

^

An error occurred between lines: 16 and 27 in the jsp file: /display.jsp

Generated servlet error:

D:\Program Files\Apache Tomcat 4.0\work\Standalone\localhost\examples\display$jsp.java:67: Class org.apache.jsp.videoBean not found.

videoBean vids = (videoBean) it.next();

^

I call this from a servlet like so:

displayBean display1 = new displayBean(videos); // videos is the name of the list which as the data in it

request.setAttribute("pricePassed", display1);

RequestDispatcher dispatcher = getServletContext().getRequestDispatcher("/display.jsp");

dispatcher.forward(request, response);

eastendersa at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 7

You have two errors. The first is this:

Undefined variable or class name: collection

This, believe it or not, is the compiler's cryptic way of telling you that you have not defined the variable "collection" before you used it in the JSP. The way to fix this is to define the variable "collection" before you use it in that JSP.

The next one is this:

Class org.apache.jsp.videoBean not found

Here the compiler, being a simple sort and prone to mistakes, assumed that since it had no idead what a "videoBean" was, and since you didn't tell it any differently, surely it's something that was supposed to be in the org.apache.jsp package and, quite sillily, told you that it couldn't find it.

The solution to this is to make sure that your videoBean class is in the classpath. Unless, of course, you really meant VideoBean...

tsitha at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 8

videoBean must be in the right place as i use it to get this list, i can display the list on the jsp infact at the moment i am display it but i just cant get it in a table, videoBean is in D:\Program Files\Apache Tomcat 4.0\webapps\examples\WEB-INF\classes\MySite and it is videoBean not VideoBean so i am not sure why i get that.

Would i define collection in the servlet which calls this? or in the bean which gets the results? In the bean that gets this list the list is called collection, this is returned to the servlet where i want to pass on the list to this jsp page.

eastendersa at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 9
If you are using scriptlets (which I don't recommend) then don't you have to import the classes you are using? They are just Java after all.
DrClapa at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 10
so i will need to import the videoBean class as well as the math and util i have never imported a class i made before it it just java.MySite.videoBean.*? thats the folder and name of calss i am using
eastendersa at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 11
hay that seems to have worked i just put MySite.* i now just get the one error about collection Undefined variable or class name where should i be setting this value then? in the servlet or here? should collection be the name of the list which as the contents inside it?
eastendersa at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 12

anybody? I have tried using the same value in the getproperty but that does not work, if i remove the scrip and just have getpropty it displays the data stored in the list, so obviously collection should be the same value of getProperty right? but trying it does not work I just get the same error

eastendersa at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...
# 13

can anybody see what i need to be doing? I can view the arraylist in the jsp by using the getProerty, I know that the list is passed to the page, but i keep getting a error for that collection part of the while loop, what should i put it as as setting it to thee same value as getProperty just results in the same error

eastendersa at 2007-7-11 23:49:26 > top of Java-index,Java Essentials,New To Java...