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 JSP not getting results from Bean Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of EJB 3 in Action this week in the EJB and other Java EE Technologies forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "JSP not getting results from Bean " Watch "JSP not getting results from Bean " New topic
Author

JSP not getting results from Bean

Justin Muir
Greenhorn

Joined: Jul 01, 2010
Posts: 11
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.
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 60046
    
  65

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.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Jul 01, 2010
Posts: 11
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

Joined: Jul 01, 2010
Posts: 11
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
dileep keely
Ranch Hand

Joined: Jun 28, 2010
Posts: 91
Can you check the class name is correct:
com.flightcentre.bean.shortlist.ShowOffers
Justin Muir
Greenhorn

Joined: Jul 01, 2010
Posts: 11
Thanks, it is correct though. I had it just as that because i was using another class as a test
Lawrence Xu
Greenhorn

Joined: Feb 11, 2004
Posts: 11
can write unit test for java class to test it
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP not getting results from Bean
 
Similar Threads
SESSION TRACKING.
Extracting Values From Single Cookie
"Type mismatch: cannot convert from Cookie to String"
JSP - cookie not processing as it should
Logout user by deleting cookie