GeeCON Prague 2014*
The moose likes Servlets and the fly likes doubt regarding how am I able to call servlet POST method with GET syntax of passing paramenter. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "doubt regarding how am I able to call servlet POST method with GET syntax of passing paramenter." Watch "doubt regarding how am I able to call servlet POST method with GET syntax of passing paramenter." New topic
Author

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: 644
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?

Thanks.




shivam singhal
Ranch Hand

Joined: Jul 15, 2012
Posts: 226

you can't..

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: 644
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: 42047
    
  64
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.


Ping & DNS - my free Android networking tools app
Amit Singh Hora
Greenhorn

Joined: Dec 23, 2012
Posts: 8
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
 
GeeCON Prague 2014
 
subject: doubt regarding how am I able to call servlet POST method with GET syntax of passing paramenter.