Passing name=value from a html form

Hi All,

I am finding strange behaviour when I try to pass a uri with a name=value pair through a html form to a servlet.

Basically, the the html form looks something like this....

<form method=get action="http://localhost:8080/jsp_tutorials/GetParameter?type=add">

Message:

<input type="text" name="param1">

<input type="submit" value="submit">

</form>

And when I click submit, the servlet is supposed to extract the "type" of action, namely "add". But surprisingly, when I do click submit, the "type=add" bit of the URI doesn't seem to go through ! Can someone explain to me why this is the case. I mean if I was to use the same uri with a simple link ie...

<a href="http://localhost:8080/jsp_tutorials/GetParameter?type=add">add</a>

it seems to go through nicely.... but with the form it just doesn't. I could solve the problem using a hidden input ie....

<form method="get" action="http://localhost:8080/jsp_tutorials/GetParameter">

Message:

<input type="text" name="param1">

<input type="hidden" name="type" value="add">

<input type="submit" value="submit">

</form>

and it seems to work too. But I am just wondering why the appended name=value pair do not go through with the uri ?

I would appreciate an explanation...

[1780 byte] By [ibn_aziza] at [2007-10-3 1:27:31]
# 1

Can you paste what is the path displayed in the browser address box when the servlet call is made?

You have specified the method as GET, so there would be some behind-the-scenes processing in which all your parameters in the form are appended as a query string to the URL and sent...and this probably is overwriting your initial query string.

Whereas, in a href, you are explicitly calling the servlet with the parameters and without any form submission.

ragh_dra at 2007-7-14 18:25:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 2
Just curious, when you change that first form to be a POST request, does the type parameter come through then?
gimbal2a at 2007-7-14 18:25:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...
# 3

in short, No. The reason being, you will have to define a separate doPost method in order to extract the parameters from the message body rather than URI.

Anyway, regarding my earlier problem, I found that the problem was actually the conflicting of hardwired form parameters and the parameters appended to the URI. They can not work together.

ibn_aziza at 2007-7-14 18:25:06 > top of Java-index,Enterprise & Remote Computing,Web Tier APIs...