Wrox Home  
Search P2P Archive for: Go

  Return to Index  

pro_jsp thread: Help with getParameter & getQueryString


Message #1 by "Richard Garcia" <richard.garcia@b...> on Thu, 9 May 2002 22:32:43
You might want to use the equals-method of the class String,
because using the '=3D=3D'-operator will only check the references of 
the
adresses, while the equals-method will check the value.

It would also be recommendable to use else if instead of each time a new
if-block, because it's a little bit more performant, but aspecially 
because it
would eliminate nullpointerexception.

Last but not least, I also recommend not to use %!-variable declaration 
for
variable that are use to contain request-information, because these 
variable
are available to all request to that page (Similar to PAGE-scope). So 
unless
you implement the SingleThreadModel this might cause problems users try 
to access
your page concurrently.

in your case the code would be something like this.
---
<%
String strVariable =3D request.getParameter("action");
out.println(intVariable);

if (intVariable=3D=3Dnull) { %>
	<table>
   		<tr>
       		<td>
           			NULL
       		</td>
   		</tr>
	</table>
<% } else if (intVariable.equals("vision")) { %>
	<table>
   		<tr>
       		<td>
           			VISION
        		</td>
    		</tr>
 	</table>
<% } else if (intVariable.equals("synopsis")) { %>
	<table>
		<tr>
     			<td>
          			SYNOPSIS
     			</td>
		</tr>
	</table>
<% } %>
---
Greetings

Bart Laeremans



-----Original Message-----
From: chanoch [mailto:mail@c...]
Sent: dinsdag 14 mei 2002 1:55
To: Pro_JavaServer_Pages
Subject: [pro_jsp] Re: Help with getParameter & getQueryString


I know some people are immensely intelligent and can give you answer 
without
seeing more (I am not joking) - but I am stuck without mroe information.
What are the hyperlink that you are using to pass the parameter values?

As a quick note, I notice you got the value and stored it in strVariable 
but
are then checking against intVariable - I take it thats an error in the
email rather than in your code. If the code is not sensitive, it would 
be
better to see a more realistic example.

chanoch
----- Original Message -----
From: "Richard Garcia" <richard.garcia@b...>
To: "Pro_JavaServer_Pages" <pro_jsp@p...>
Sent: Thursday, May 09, 2002 10:32 PM
Subject: [pro_jsp] Help with getParameter & getQueryString


> I have a JSP page that has a table in the middle. There are 5 links on 
top
> of the page that, when clicked, will change the content in the table. 
I
> pass a querystring value back to the same page, and the content in the
> table should change based on the questring value. Here's a really 
simple
> example of the code that I'm using to try and do this:
>
>
> <%!
> String strVariable;
> %>
> <%
> strVariable =3D request.getParameter("action");
> out.println(intVariable);
> if (intVariable=3D=3Dnull) {
> %>
> <table>
>    <tr>
>        <td>
>            NULL
>        </td>
>    </tr>
> </table>
> <%
>        }
>        if (intVariable=3D=3D"vision") {
> %>
> <table>
>    <tr>
>        <td>
>            VISION
>        </td>
>    </tr>
> </table>
> <%
>        }
> if (intVariable=3D=3D"synopsis") {
> %>
> <table>
>    <tr>
>        <td>
>            SYNOPSIS
>        </td>
>    </tr>
> </table>
> <%
>        }
> %>
>
>
> I've tried both request.getParameter and request.getQuerystring to no
> avail. Also, the code does compare the null value to intVariable and 
that
> table does show up correctly, but the others don't. Has anyone else 
had
> this problem and know what I'm doing wrong? That's in advance for your
> help.



  Return to Index