This week's book giveaway is in the Servlets forum.
We're giving away four copies of Murach's Java Servlets and JSP and have Joel Murach on-line!
See this thread for details.
The moose likes Servlets and the fly likes NullPointerException and request.getParameter() Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Murach's Java Servlets and JSP this week in the Servlets forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "NullPointerException and request.getParameter()" Watch "NullPointerException and request.getParameter()" New topic
Author

NullPointerException and request.getParameter()

harshad kadam
Greenhorn

Joined: Mar 19, 2011
Posts: 8
in servlet i am taking value from URL String callback = request.getParameter("_callback"); problem is &_callback can be there or not, i am getting nullPointerException if &_callback is not there in URL. I tried to catch the exception but didn't work. is there any way to check whether request.getParameter() is null or not? if it is null, i want to execute a part of code and if not, other part.
sudhir nim
Ranch Hand

Joined: Aug 29, 2007
Posts: 212

getParameter returns the value of a request parameter as a String, or null if the parameter does not exist. It does not through NullPointerException if parameter does not exist. Make sure that the request object on which you are calling getParameter is not null. Look at this servlet request Article for details on methods for request parameters.


[Servlet tutorial] [Servlet 3.0 Cook Book]
Mohamed Sanaulla
Saloon Keeper

Joined: Sep 08, 2007
Posts: 3064
    
  33

You could do this- callBack != null or callBack == null.


Mohamed Sanaulla | My Blog
harshad kadam
Greenhorn

Joined: Mar 19, 2011
Posts: 8
yes..it worked.. i had written [!callback.equals(null)] i changed it to [callback != null]. resolved.
 
It is sorta covered in the JavaRanch Style Guide.
 
subject: NullPointerException and request.getParameter()
 
Similar Threads
null pointer exception after response.sendRedirect() in jsp page.
Error in hashtable put method
Null pointer
Problem in updating the fields to database
JSP form processing