doubt regarding how am I able to call servlet POST method with GET syntax of passing paramenter.
Monica. Shiralkar
Ranch Hand
Joined: Jul 07, 2012
Posts: 182
posted
0
I am handling requests in servlet by POST method. Now I am making a call to this sevelet from a Javascript by using .Passing paramenter like this is GET request style.But this is being handled by POST method in servlet.I am confused that why does it work.
inside the servlet:
Inside the javascript:
This works perfectly but I fail to understand why so because passing parementer in URL is GET style how does POST method of servlet handle this?
The Service method of your servlet rechognize weather its a get, post, head, trace, put, deleat .. etc request.. and then call the same overrided method in your servlet..
if you try like that::
you use http method GET from you html.. and forwaring the request to any servlet which does'nt override doGet method..
then you will get Failure..
Monica. Shiralkar
Ranch Hand
Joined: Jul 07, 2012
Posts: 182
posted
0
If we cant then how does the above code work fine. I am sending parameters in URL (which is the GET way) and it still gives the response without giving error.
Ulf Dittmer
Marshal
Joined: Mar 22, 2005
Posts: 35220
7
posted
0
It's still a request parameter. The difference is that with a GET, *all* parameters are sent as part of the URL (there is no request body), whereas with POST parameters are sent in the request body. Unless you take pains to send parameters as part of the URL as well, like you did. If you initiate a proper form submission and look at the HTTP in transmission (using a tool like the LiveHTTPHeader plugin for Firefox) you'll see the difference.
when you use Post method while submitting a form say
<form action="something(say your servlet)" method="post">
<input type="text" name="username"/>
</form>
Now at the time it goes to servlet you do request.getparameter("username")--->right but in browser url you will not see something like
http://localhost:8080/<ur servlet>?usernaame=xyz
becoz the above url is produced when get method is used
the way you are sending it explicitly by using javascript is like in a get manner but yet you can use getParameter