Win a copy of Mesos in Action this week in the Cloud/Virtualizaton forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doubt regarding how am I able to call servlet POST method with GET syntax of passing paramenter.

 
Monica Shiralkar
Ranch Hand
Posts: 842
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 231
Java Notepad Tomcat Server
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 842
1
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Rancher
Posts: 42967
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Amit Singh Hora
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic