• 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

Content Type issue

 
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi,

I'm trying to do the foloowing with the HTML and servlet code given below.
Downlaod a jar file if the user checks the download button; else show him an error page.

The 'if' part works fine. The 'else' part throw NullPointerException. It does not even print the "in else" statement to the console. Please help.
Have been trying for a long time on this.

Thanks in advance,
Rick

 
Ranch Hand
Posts: 364
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Which line is throwing the exception?
What does request.getParameter("download") return when the checkbox is left unchecked?
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator


Browsers send nothing if a checkbox is unchecked.
This means that getParameter will return null in that case.
Null pointers don't have an .equals(..) method.

You'll need to either check for null before trying to call equals or just check for null. Another alternative is to turn the test around.


Since the string literal "on" will always be a valid string, you can call its equals method instead of trying to call it on the results from getParameter.
 
Rick Shroff
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Rick Shroff:
Hi,

I'm trying to do the foloowing with the HTML and servlet code given below.
Downlaod a jar file if the user checks the download button; else show him an error page.

The 'if' part works fine. The 'else' part throw NullPointerException. It does not even print the "in else" statement to the console. Please help.
Have been trying for a long time on this.

Thanks in advance,
Rick

 
Rick Shroff
Greenhorn
Posts: 10
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks Edvins and Ben!

The problem was indeed due to the 'null' returned when the download checkbox was not checked.

I used the following as suggested by Ben-



And could correctly display the Error page. Thanks!!
reply
    Bookmark Topic Watch Topic
  • New Topic