Win a copy of Programmer's Guide to Java SE 8 Oracle Certified Associate (OCA) this week in the OCAJP forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

NullPointerException

 
amit bhadre
Ranch Hand
Posts: 124
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How to Handle NullPointerException in JSP?
 
Prabhu Venkatachalam
Ranch Hand
Posts: 502
Java jQuery Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It is not advicable to catch RuntimeException and its subclasses.

Do you have any specific reasons to do? If so,

1. Write a JSP with page attribute isErrorPage="true", so that you will get exception implicit object avaliable for you to see what exception occured.

2. In the other JSP you can add errorPage="<pointing to the previous JSP>".

OR

1. Step-1 above

2. In web.xml(Deployment Decriptor),

<error-page>
<exception-type>java.lang.NullPointerException</exception-type>
<location>(pointing to the previous JSP you created)</location>
</error-page>
 
Deepak Bala
Bartender
Posts: 6663
5
Firefox Browser Linux MyEclipse IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you think you can recover from the exception I would suggest a c : catch block. What part of your code throws this ?
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic