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

java.lang.NullPointerException? ResultSet issue I cant seem to solve  RSS feed

 
S.R. Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I dont know why I am getting the exception. I've re-written the code several times and still can not see it.

Patient class:


My Servlet that will be my only controller on my web application :





and my JSP page I am trying to get results pulled from my database through a basic search where I cant figure out why it wont work.. Thanks so much


 
Tim Cooke
Marshal
Posts: 3858
233
Clojure IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You're going to need to be a bit more specific than "it won't work".

What does the stack trace look like? Where in your code is the NullPointerException thrown?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why is there Java code in your JSP?
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The following is also a huge anti-pattern:

GETs and POSTs should rarely (almost never) do the same thing.

And, servlets should not have constructors. Yours does nothing, so why is it even there?
 
S.R. Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator


So the error is thrown as soon as I assign the resultset

Also there is java in my jsp because my instructors wont let us use JSTL, in fact I'm probably going to get drilled for even using a servlet instead of haveing a processing page be called as the form post.

I put doPost because the tutorial I was watching the instructor is using his servlet as the home page so only one instance of do Get was called and he had to copy the same thing to doPost and I just happened to come across the a site showing tips and that was one of them. Additionally I added a filter for login and noticed instead of the one instance of doGet being called it instead went straight to the filter and to the do post method so I'm not sure if I will need a do Get at any time but of course I cant know as I'm new to servlets. My intention in the jsp page is to enter a First Name and Last Name and retrieve the record from a database and that is what is not working. Thanks for reading!

 
Tapas Chand
Ranch Hand
Posts: 614
9
BSD Java
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The error messages clearly say "myPatient" is null.
Have you checked the value of "myPatient" after getting from session?

The JSP looks terrible.
I do not know what you will learn with such an instructor who forbids to use JSTL and EL and Servlet.
 
S.R. Clark
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I redid my JSP from scratch again and what i found out is the use of Capital letters in my beans for the variables were against the java convention and the set property was not finding them so after redoing those in common letters I do seem to be getting a result set but not getting it to display on page



issue.JPG
[Thumbnail for issue.JPG]
Getting the ResultSet but cant display it
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 66184
146
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You should have mentioned this was an assignment with restrictions versus a real-world problem.

Be advised: in the real world, Java in a JSP is a huge no-no.

 
Rob Nurdaer
Greenhorn
Posts: 4
Eclipse IDE Java Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Try checking your getParameter items for null just in case but I don't see anything off hand. Where is your stack?
 
Stefan Evans
Bartender
Posts: 1836
10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
One thing I have noticed, is that you have fallen into the common pitfall of attribute vs parameter.



I believe that the calls to request.getAttribute in this snippet should be request.getParameter

 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!