Win a copy of Beginning Java 17 Fundamentals: Object-Oriented Programming in Java 17 this week in the Java in General forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Tim Cooke
  • Campbell Ritchie
  • Ron McLeod
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Junilu Lacar
  • Rob Spoor
  • Paul Clapham
Saloon Keepers:
  • Tim Holloway
  • Tim Moores
  • Jesse Silverman
  • Stephan van Hulst
  • Carey Brown
Bartenders:
  • Al Hobbs
  • Piet Souris
  • Frits Walraven

Head First Servlets and JSP simple exercise problem

 
Greenhorn
Posts: 10
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 10
Hibernate Eclipse IDE Java
  • Likes 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Good catch.
 
Nikolaos Plastiras
Greenhorn
Posts: 10
Firefox Browser Java Windows
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
Sheriff
Posts: 67620
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Don't be too embarrassed. I didn't see it either on first inspection.
 
Bartender
Posts: 1111
Eclipse IDE Oracle VI Editor
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
WHAT is your favorite color? Blue, no yellow, ahhhhhhh! Tiny ad:
Building a Better World in your Backyard by Paul Wheaton and Shawn Klassen-Koop
https://coderanch.com/wiki/718759/books/Building-World-Backyard-Paul-Wheaton
reply
    Bookmark Topic Watch Topic
  • New Topic