Win a copy of Kotlin in Action this week in the Kotlin forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

JSP Servlets and ResultSet  RSS feed

 
Hardik Trivedi
Ranch Hand
Posts: 252
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi all genius people,

I am working on jsp - servlets project. I came across a very interesting problem.
The project is following MVC pattern.In my model classes I am returning a resultset object (which I shouldn't,but due to some reason I have to do this. ). So the problem is I am catching the returned ResultSet's object in JSP. In JSP NullPointerException is coming.

I checked that resultset is not empty.

Model class Code



JSP Code


Can any one give me the solution. OR guidelines.
 
Nicola Garofalo
Ranch Hand
Posts: 308
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hallo Hardik,
i don't like your MVC, it's not really an MVC what i see.

Anyway the problem could be at



I have two questions about that

1) Are you sure that User is not null?
2)Are you absolutely sure that the method getUser(userId) does not return null?

Try to debug your code, put a breakpoint at the above line and see when exactly you get the NullPointerException.
Probably that will happen when you call the getString method of your ResultSet



If you have problems in debugging, just post the stack trace printed.
 
Ulf Dittmer
Rancher
Posts: 42972
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I agree, this is not MVC at all. No ResultSet should come near the view layer, and no JSP should contain Java code (much less DB code).

You mention a NullPointerException - which object is null?
 
prabhu mannu
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Have you read the concept of MVC first.
JSP are suppose to be view, a presentation layer.
Why are you using a resultset here.
And What does the Object User stands for ?
If its bean how could it use resultset ?
To me it seems,even for a beginner, your code is highly irrelevant.

here is a simple version how it should be done

User Bean



Dao


part of action code;



jsp code (you are using scriptlets its ancient history. try to learn jstl and other tags too not that hard to learn them



this should give you a rough idea about MVC and how it works

NOTE this is just a rough code not a working one..
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!