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 / January 2007

Tip: Looking for answers? Try searching our database.

servlet and forms and long strings

Thread view: 
Damo - 03 Jan 2007 21:40 GMT
Hi,
I have a form that the user enters information into. This information
is then passed to a servlet for processing. The problem is the form
doesnt seem to pass strings of more than one word . eg. if I put in
"java" , this will be passed to the servlet , but if i put in "java
program" it does not work.

Its being passed using:
query = request.getParameter("fieldname");

The form uses the POST method

Does anyone know why?
Daniel Pitts - 03 Jan 2007 21:50 GMT
> Hi,
> I have a form that the user enters information into. This information
[quoted text clipped - 9 lines]
>
> Does anyone know why?

Does your form look more or less like this:
<form action="/myapp/" method="post>
<input name="fieldname" value="" />
<input type="submit" />
</form>

Anyway, its impossible for us to know why without a lot more context
about whats going on.  When you say it does not work, that can mean
many many things.  Does it 404? Does it 500? Does it give the wrong
results? Do you log the value to verify that the value is not what you
expect?

So, help us help you, give us some details.

Hope this helps,
Daniel.
Damo - 03 Jan 2007 22:05 GMT
Yes, the form is pretty much identical to that. What I'm writing is a
form of metasearch. My form takes in a query and sends the query to
appropriate engine.
It does'nt give a 404 or 500, it just returns a blank page. With a one
word query it returns the correct page.
If I get the query using the above and then use
out.println(query) ............it will print the correct query, so I
figure its no passing the value(if its a multiple word query) from the
servlet to the search engine.
Daniel Pitts - 03 Jan 2007 22:27 GMT
> Yes, the form is pretty much identical to that. What I'm writing is a
> form of metasearch. My form takes in a query and sends the query to
[quoted text clipped - 5 lines]
> figure its no passing the value(if its a multiple word query) from the
> servlet to the search engine.

It could also be that you need to escape multi-word queries.  Its hard
to tell without knowing your search index.
Juha Laiho - 04 Jan 2007 15:52 GMT
"Damo" <cormacdebarra@gmail.com> said:
>Yes, the form is pretty much identical to that. What I'm writing is a
>form of metasearch. My form takes in a query and sends the query to
[quoted text clipped - 5 lines]
>figure its no passing the value(if its a multiple word query) from the
>servlet to the search engine.

Hmm, this isn't nice. You're changing your problem description.

At first you let us know that information is not getting passed to the
servlet. Now you're telling that you can see the information in the
servlet. So, the form part of the question is irrelevant; the issue
is what does your servlet do to the string it received - how it is
passed on, and what kind of interface there is to the search side.
Signature

Wolf  a.k.a.  Juha Laiho     Espoo, Finland
(GC 3.0) GIT d- s+: a C++ ULSH++++$ P++@ L+++ E- W+$@ N++ !K w !O !M V
        PS(+) PE Y+ PGP(+) t- 5 !X R !tv b+ !DI D G e+ h---- r+++ y++++
"...cancel my subscription to the resurrection!" (Jim Morrison)

Daniel Pitts - 04 Jan 2007 17:49 GMT
> "Damo" <cormacdebarra@gmail.com> said:
> >Yes, the form is pretty much identical to that. What I'm writing is a
[quoted text clipped - 14 lines]
> is what does your servlet do to the string it received - how it is
> passed on, and what kind of interface there is to the search side.

Yeah, It could be that he worked out that it wasn't the problem he
thought it was, and instead was a different problem.

I'm assuming since he hasn't posted a question since then (which he
hasn't), he's figured out the rest on his own.
Damo - 04 Jan 2007 20:07 GMT
I was away for the last day.
I've discovered its nothing to do it passing long Strings(Sorry!). The
right query is forwarded. Whats causing the problem is a
ParserConfigurationException. I dont know why this would happen though,
it only appears with multiple word queries.
Daniel Pitts - 04 Jan 2007 20:15 GMT
> I was away for the last day.
> I've discovered its nothing to do it passing long Strings(Sorry!). The
> right query is forwarded. Whats causing the problem is a
> ParserConfigurationException. I dont know why this would happen though,
> it only appears with multiple word queries.
What search engine are you using?
Damo - 04 Jan 2007 20:22 GMT
> What search engine are you using?

yahoo. . It works fine with asingle word query
Damo - 04 Jan 2007 20:48 GMT
Its a 400 error the browser is returning .
the URL that i am sending to the search engine would be in the form :

http://search.yahoo.com/search?&p=java program&n=100

If you type this directly into the browser yahoo will add "%20" between
java and program.
So i guess if you're opening a connection from a program it does'nt do
this. Can I account for this before i send the query?
Daniel Pitts - 04 Jan 2007 20:53 GMT
> Its a 400 error the browser is returning .
>  the URL that i am sending to the search engine would be in the form :
[quoted text clipped - 5 lines]
> So i guess if you're opening a connection from a program it does'nt do
> this. Can I account for this before i send the query?

Look at java.net.URLEncoder
Specifically, java.net.URLEncoder.encode(urlString, "UTF-8");
Damo - 04 Jan 2007 21:11 GMT
excellent, cheeers ... that did the trick
Manish Pandit - 03 Jan 2007 23:39 GMT
> Hi,
> I have a form that the user enters information into. This information
[quoted text clipped - 9 lines]
>
> Does anyone know why?

This should give you the exact word(s) typed in. Try changing the form
method (for debugging purposes) to GET, and see if the URL you get on
the browser address bar shows the string. The string should show up as
escaped (something like query.do?fieldname=java+program. Other than
that, given the context and info you provided, there seems to be no
reason for the string to break between the browser and the servlet.

-cheers,
Manish


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.