File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
The moose likes JSP and the fly likes Head First Servlets and JSP simple exercise problem Big Moose Saloon
  Search | Java FAQ | Recent Topics
Register / Login
JavaRanch » Java Forums » Java » JSP
Reply Bookmark "Head First Servlets and JSP simple exercise problem" Watch "Head First Servlets and JSP simple exercise problem" New topic
Author

Head First Servlets and JSP simple exercise problem

Nikolaos Plastiras
Greenhorn

Joined: Feb 08, 2012
Posts: 2

Firstly, hello to everybody since this is my first post.

I am trying to run the Head First Servlets and JSP chapter's 3 beer example like so many others in here.
I have done every step successfully till the time i had to run a .jsp for the first time.
The result.jsp code is:

but when i try to run it i get this from tomcat (and some other stuff):


I read all the topics about others having problem with this exercise and none had a similar one.
If i change the result.jsp file to this:

everything runs smoothly and the message i printed properly.

for the record, the class with the setAttribute method is this:

Is there a problem with request.setAttribute("styles", result) in the .class file; ? If there was one, why tomcat sais the problem is in the Iterator it = styles.iterator();iterator line in the .jsp file?

Anyone got any ideas?
Thanks in advance.
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

Verfiy that this line:

List result = be.getBrands(c);

is doing what you expect. A possible cause of the issue is that result is null.


[Smart Questions] [JSP FAQ] [Books by Bear] [Bear's FrontMan] [About Bear]
Deepak Soni
Greenhorn

Joined: Jul 23, 2011
Posts: 10

hey...
In your jsp code you are getting attribute value for 'style' : List styles = (List)request.getAttribute("style"); at line 9
but in your servlet code you set the value for 'styles' :request.setAttribute("styles", result); at line 16
that cause the exception...

replace your jsp code at line 9 with List styles = (List)request.getAttribute("styles");


OCPJP 6
OCE J2EE 6 JSP and Servlets Developer
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

Good catch.
Nikolaos Plastiras
Greenhorn

Joined: Feb 08, 2012
Posts: 2

OH MY GOD, i spent 3 hours reading every others' problems, documentations about tomcat, jsp, jstl and jdk just because i was too tired at 4am to check for the most stupidest errors. I feel so embarrassed... Thanks for the help. Next time, i'll get a good night sleep.
Bear Bibeault
Author and opinionated walrus
Marshal

Joined: Jan 10, 2002
Posts: 50693

Don't be too embarrassed. I didn't see it either on first inspection.
Wendy Gibbons
Bartender

Joined: Oct 21, 2008
Posts: 774

Nikolaos Plastiras wrote:OH MY GOD, i spent 3 hours reading every others' problems, documentations about tomcat, jsp, jstl and jdk just because i was too tired at 4am to check for the most stupidest errors. I feel so embarrassed... Thanks for the help. Next time, i'll get a good night sleep.


don't be embarressed, it is only after this first one you learn to check and double check those pesky strings,
makes you wish there was some way you could make constants between the jsp and servlet for that type of stuff.
 
 
subject: Head First Servlets and JSP simple exercise problem
 
Threads others viewed
result.jsp not found 404 error
output of result.jsp
Why this EL code part is not working
Compiling result.jsp (page 89 HFSJ)
HFSJ struts Example pgm
IntelliJ Java IDE