• 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:
  • Campbell Ritchie
  • Tim Cooke
  • paul wheaton
  • Jeanne Boyarsky
  • Ron McLeod
Sheriffs:
  • Paul Clapham
  • Liutauras Vilda
  • Devaka Cooray
Saloon Keepers:
  • Tim Holloway
  • Roland Mueller
Bartenders:

JSP not getting results from Bean

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi

I am trying to create an "Add to shortlist" functionality for our website. I have a jsp and a java class which should connect to the database and then display the results according to the specific "offerid" that the user added.

I am using cookies to store the offerid's and it displays the cookie values (offerid's) on the page but doesn't get the data from the bean, in the Tomcat console its telling me NullPointerException, but i'm really battling because i'm quite new to this so don't know what i'm doing wrong.

Here is my jsp so anyone can try tell me if something is wrong in it. Sorry i'm posting all this it's just i'm getting no where and really don't know where i'm going wrong now



And here is my bean (class)



Pleeeeease can someone out there help me, i have no-one to ask and my job is on the line as i'm on a 3month probation here.
 
Sheriff
Posts: 67753
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
Welcome to the Ranch.

For me, step 1 would be to refactor the JSP to include no Java scriptlets. Scriptlets have been discredited since the introduction of JSP 2.0 over 8 years ago.

You might want to read this article for some ideas on modern web application structure.

As it stands, you've posted a lot of code without any indication of where the error is occurring. Does not the error message include information that helps to narrow the location of the problem down? You might want to at least include that in your post.

Even better would be to narrow down the scope of the code you post to that which is causing the issue.
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This isn't really the kind of information I'd store in a cookie, either-better to keep in session, and persist to a DB if required.

But Bear's right-you've got too much Java in your JSP, and too much HTML in your Java.
 
Justin Muir
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks a lot for your guys reply, sorry i know i posted a lot the reason being that i have just been trying for quite a while and can't seem to sort it out and don't
know where the problem is, so thought if i give most of the code, someone might be able to see a problem.

And yes, i know its too much java in the scriptlet but i'm still new with this subject and don't know too much on how to use servlets etc.

The reason i'm using cookies is because our site runs on 2 servers and so if i use a seeion, it can transfer to the other server and then will be a different session (I think).
So i've been told the best way is to use cookies...

But thanks, i will try do some more research and see if i can find the specific problem
 
Justin Muir
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Bear Bibeault wrote:Welcome to the Ranch.

For me, step 1 would be to refactor the JSP to include no Java scriptlets. Scriptlets have been discredited since the introduction of JSP 2.0 over 8 years ago.

You might want to read this article for some ideas on modern web application structure.

As it stands, you've posted a lot of code without any indication of where the error is occurring. Does not the error message include information that helps to narrow the location of the problem down? You might want to at least include that in your post.

Even better would be to narrow down the scope of the code you post to that which is causing the issue.




Thanks Bear, but yes its telling me that the error is occuring in the getOffers() method, with a nullPointerException.

I am passing through the offerid from the JSP which is stored in the cookie, and so i don't know why this is causing the problem.

I found that it is getting caught in the last catch block of the getOffers() method. So don't know if you might know why this is then?

Thanks in advance
 
Ranch Hand
Posts: 112
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Can you check the class name is correct:
com.flightcentre.bean.shortlist.ShowOffers
 
Justin Muir
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks, it is correct though. I had it just as that because i was using another class as a test
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
can write unit test for java class to test it
 
We must storm this mad man's lab and destroy his villanous bomb! Are you with me tiny ad?
Smokeless wood heat with a rocket mass heater
https://woodheat.net
reply
    Bookmark Topic Watch Topic
  • New Topic