aspose file tools*
The moose likes Servlets and the fly likes Content Type issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "Content Type issue" Watch "Content Type issue" New topic
Author

Content Type issue

Rick Shroff
Greenhorn

Joined: Mar 06, 2008
Posts: 10
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



Cheers,<br />Rick<br />SCJP
Edvins Reisons
Ranch Hand

Joined: Dec 11, 2006
Posts: 364
Which line is throwing the exception?
What does request.getParameter("download") return when the checkbox is left unchecked?
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410



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.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Rick Shroff
Greenhorn

Joined: Mar 06, 2008
Posts: 10
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

Joined: Mar 06, 2008
Posts: 10
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!!
 
Don't get me started about those stupid light bulbs.
 
subject: Content Type issue