• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

NullPointerException and request.getParameter()

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 212
Eclipse IDE Spring Ubuntu
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Bartender
Posts: 3225
34
IntelliJ IDE Oracle Spring Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You could do this- callBack != null or callBack == null.
 
harshad kadam
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
yes..it worked.. i had written [!callback.equals(null)] i changed it to [callback != null]. resolved.
reply
    Bookmark Topic Watch Topic
  • New Topic