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.
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
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).]
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).]
Or in this case, the even more concise, but a bit more complex:
Joined: Mar 02, 2000
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)