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

JSP output problem

Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
I'm probably missing something really obvious here but I'm trying to write a JSP that will take parameters passed into it from a HTML page and use those in the page generated by the JSP.
The problem is that sometimes one or two parameters may be empty.
here's a sample of my code.

... and so on.
The thing is that say if q3 had no value, the JSP generates an empty table row ... I thought that by using the if statements I would prevent that from happening but it doesn't work!
Anyone got any ideas?
[This message has been edited by Angela Poynton (edited September 28, 2000).]


Pounding at a thick stone wall won't move it, sometimes, you need to step back to see the way around.
Madhav Lakkapragada
Ranch Hand

Joined: Jun 03, 2000
Posts: 5040

As I understand the API for getParameter(),
a null value is returned ONLY
if the parameter is not there.
if the parameter exists, then I don't think it will
return a null. Would be interestiing to see what it does.
Hope I am right.....
Regds.
- satya

Take a Minute, Donate an Hour, Change a Life
http://www.ashanet.org/workanhour/2006/?r=Javaranch_ML&a=81
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
A ha!! it just came to me!!

There might be a neater way of writing it .. but I have a cold and my brain may as well be made of fudge today!!
Anyway this works!!
[This message has been edited by Angela Poynton (edited September 29, 2000).]
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Angela wrote: my brain may as well be made of fudge today, or the middle of those creme eggs the Americans can't find ...
Meanwhile, a useful idiom I have taken to doing, is to always put the constant string part of an ".equals" or ".equalsIgnorecase" first. That way you are guaranteed never to get a NullPointerException, even if the parameter is null. I'd also make use of temporary variables to simplify the JSP code a bit. So I'd recode your page as something like:

[This message has been edited by Frank Carver (edited September 29, 2000).]


Read about me at frankcarver.me ~ Raspberry Alpha Omega ~ Frank's Punchbarrel Blog
Frank Carver
Sheriff

Joined: Jan 07, 1999
Posts: 6920
Or in this case, the even more concise, but a bit more complex:
Angela Poynton
Ranch Hand

Joined: Mar 02, 2000
Posts: 3143
Frank,
If i told you I loved you would you not take it too seriously!!
I LOVE YOU!! I knew there must be a better way of going about it ... like I said my brain is Fudge!
I love the seond idea ... would make my file sooo much smaller!!
I'm actually using this JSP to dynamically create FAQ pages for this site, and of course to give me a bit of JSP writing practice (or that's what i'm telling my boss)
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: JSP output problem