File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Soft Skills: The software developer's life manual this week in the Jobs Discussion forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Head First Servlets and JSP simple exercise problem

 
Nikolaos Plastiras
Greenhorn
Posts: 7
Firefox Browser Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Deepak Soni
Greenhorn
Posts: 10
Eclipse IDE Hibernate Java
  • 2
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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");
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Good catch.
 
Nikolaos Plastiras
Greenhorn
Posts: 7
Firefox Browser Java Windows
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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 ninkuma
Marshal
Pie
Posts: 64171
83
IntelliJ IDE Java jQuery Mac Mac OS X
  • 1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Don't be too embarrassed. I didn't see it either on first inspection.
 
Wendy Gibbons
Bartender
Posts: 1107
Eclipse IDE Oracle VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
It is sorta covered in the JavaRanch Style Guide.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic