I have an if statement in my jsp page that shows one piece of html if true and another if it's false. This works. I need to have a parameter value, on a href link that is on this same page, so that if that link is clicked, the if statement will be true, and the page will be redisplayed with the specified piece of html. I hope I explained well and someone knows how to do this. Thanks!
I think I understand. On the calling page, the href uri needs to include a parameter. Example < a href="http://www.javaranch.com/index.jsp?showPart1=true">JavaRanch.... In your jsp you can test the value in a manner similar to: < % String showIT = request.getParameter("showPart1"); if(showIT.equals("true")) {...... [ February 15, 2002: Message edited by: Carl Trusiak ]
Thanks a lot! However, I'm getting a null error. <a href="index.jsp?showOSMain=true"> The showOSMains parameter has a null value whe the jsp runs instead of a "true" value. Any hint as why the jsp page is not recognizing this value?
It's showOSMain, I misspelled it in the msg, sorry. The page compiles and builds ok. If I substitute the <% String showString = "false"; showString = request.getParameter("showOSMain"); if (showString.equals("true")) { %> <jsp:include page="opensource/opensourcemain.html" flush="true" />... by: if (true) { %> ... It runs fine and gives me the correct page. It's just when the parameter [showString.equals("true")] gets passed it has a null value, and that is a boo boo.
You definately have something miss typed. I ran a test real quick the href : < a href="testCat.jsp?showOSMain=true">Test it Carl</a> and textCat.jsp simply < %= request.getParameter("showOSMain") %> And it prints true so, check your spellings between the two very closely.
Originally posted by Carl Trusiak: You definately have something miss typed. I ran a test real quick the href : < a href="testCat.jsp?showOSMain=true">Test it Carl</a> and textCat.jsp simply < %= request.getParameter("showOSMain") %> And it prints true so, check your spellings between the two very closely.
Well, I ran your test on my jsp and the value I get is null. The null value actually now makes sense, probably it happens because the link hasn't been clicked yet (but then how did you get it??). But when I use an if statement to account for the null value (if null display x, else y), I get the same nullpointerexception error.
Ok, I got it. The problem: on my if statement, I was testing for (showString.equals(null)) Solution: (showString.equals("null")) It was the quotes around the null inside the operation that were missing that was the problem. Thank you so much for your help.
Actually, that did work at some point but then it stoped working again. The problem is that .equals() does not take a null value for comparisson. That has to be done with ==.
i blog here: carlisia.com
When evil is afoot and you don't have any arms you gotta be hip and do the legwork, but always kick some ... tiny ad:
a bit of art, as a gift, that will fit in a stocking