Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsWhite Papers
Discussion GroupsFirst AidDatabasesJavaBeansGUIJava 3DVirtual MachineCORBASecurityToolsGeneral
Java DirectoryOpen Source ProjectsSample Book ChaptersUser GroupsWeb Resources
Related Topics
Databases.NETMore Topics ...

Java Forum / General / November 2007

Tip: Looking for answers? Try searching our database.

parsing query string parameter causes server to hang

Thread view: 
inetquestion - 20 Nov 2007 21:30 GMT
I am trying to add a check in my web app to look for a query string
parameter and produce different output depending on the value of
param1 if it exists.  With the code below it works fine if there is no
query string parameters, but hangs if there are any present.  I'm new
to Java, so any help would be appreciated.

Enumeration e = request.getParameterNames();
while (e.hasMoreElements())
{
    String[] debug_array = request.getParameterValues("param1");
    debug = (String) debug_array[0];
}

-Inet
Manish Pandit - 20 Nov 2007 21:40 GMT
> I am trying to add a check in my web app to look for a query string
> parameter and produce different output depending on the value of
[quoted text clipped - 11 lines]
>
> -Inet

That is because e.hasMoreElements() is returning true all the time.
You need to increment the counter by using e.nextElement( ) and use
that to get the parameter values.

while(e.hasMoreElements()){
 String[] debugArray = request.getParameterValues((String)
e.nextElement());
 debug = (String) debug_array[0];

}

-cheers,
Manish
Owen Jacobson - 20 Nov 2007 21:41 GMT
> I am trying to add a check in my web app to look for a query string
> parameter and produce different output depending on the value of
[quoted text clipped - 11 lines]
>
> -Inet

You never step the enumeration forward, so e.hasMoreElements will
always return the same value.  See the javadocs for
java.util.Enumeration for details.
Joe Attardi - 20 Nov 2007 21:50 GMT
> Enumeration e = request.getParameterNames();
> while (e.hasMoreElements())
> {
>     String[] debug_array = request.getParameterValues("param1");
>     debug = (String) debug_array[0];
> }

Manish and Owen already answered your question, but just to add my
$0.02. Since debug_array is a String[], you don't have to cast
debug_array[0] to a String.

Signature

Joe

Manish Pandit - 20 Nov 2007 23:08 GMT
> Manish and Owen already answered your question, but just to add my
> $0.02. Since debug_array is a String[], you don't have to cast
> debug_array[0] to a String.
>
> --
> Joe

Ah! Good catch :)

-cheers,
Manish
Daniel Pitts - 20 Nov 2007 23:18 GMT
>> Enumeration e = request.getParameterNames();
>> while (e.hasMoreElements())
[quoted text clipped - 6 lines]
> $0.02. Since debug_array is a String[], you don't have to cast
> debug_array[0] to a String.

Now, for my 2 cents...
If you are using getParameterValues("param1"), don't use
getParameterNames at all..., actually, since you only use the first one,
try: replacing that entire snippet with:

debug = request.getPramaterValue("param1");

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Daniel Pitts - 20 Nov 2007 23:21 GMT
> If you are using getParameterValues("param1"), don't use
> getParameterNames at all..., actually, since you only use the first one,
> try: replacing that entire snippet with:
>
> debug = request.getPramaterValue("param1");

Or, if you're like me and don't use spell check,
debug = request.getParameterValue("param1");

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

Joe Attardi - 21 Nov 2007 00:30 GMT
> Or, if you're like me and don't use spell check,
> debug = request.getParameterValue("param1");
Isn't it request.getParameter("param1") for a single parameter?
Daniel Pitts - 21 Nov 2007 00:49 GMT
>> Or, if you're like me and don't use spell check,
>> debug = request.getParameterValue("param1");
> Isn't it request.getParameter("param1") for a single parameter?

Probably, but the point was made:
Read the Javadoc and choose the best method :-)

Signature

Daniel Pitts' Tech Blog: <http://virtualinfinity.net/wordpress/>

inetquestion - 21 Nov 2007 02:40 GMT
Cool!  thanks for your assistance.

I made the changes you pointed out and its working perfectly.  :)
Roedy Green - 21 Nov 2007 03:32 GMT
On Tue, 20 Nov 2007 13:30:13 -0800 (PST), inetquestion
<inetquestion@hotmail.com> wrote, quoted or indirectly quoted someone
who said :

>while (e.hasMoreElements())

see http://mindprod.com/jgloss/jcheat.html#LOOPS

for the various loop idioms, including Enumeration loops.
Signature

Roedy Green Canadian Mind Products
The Java Glossary
http://mindprod.com



Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.