• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Ranch Hand
Posts: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.




 
Ranch Hand
Posts: 231
Tomcat Server Notepad Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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: 2925
13
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Rancher
Posts: 43081
77
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic