This week's book giveaway is in the Clojure forum.
We're giving away four copies of Clojure in Action and have Amit Rathore and Francis Avila on-line!
See this thread for details.
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doPost and doGet

 
lakshmi v.samy
Ranch Hand
Posts: 30
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi friends
I have one doubt

In one html
<form action="myservlet" method=Get>

In another html
<form action="myservlet" method=Post>


please help me what method(doGet,doPost or service) I can override in servlet-(myservlet is extending HttpServlet)to do the actions.I want to have only one servlet(myservlet) for both the html files.
Thanks in advance.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You can override doPost(for POST) and doGet(for GET) in a single Servlet class.
 
Arunprasath Rajmohan
Greenhorn
Posts: 4
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello lakshmi


If u use post in ur html form then u have to use doPost in servlet.
If u use get in ur html form then u have to use doPost or doGet in servlet.

But what u should not is if u use post in html and if u use doGet in servlet it will give a nasty error

HTML SERVLET
POST- doPost()
GET- doGet(),doPost()

the below combination will rise an error:
HTML SERVLET
POST doGet()
 
Eddy Lee Sin Ti
Ranch Hand
Posts: 135
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Usually you want to use POST method for form submission. By default, form method is GET.

Yup, usually I overrided both and one of the method just delegate the call to another.
[ February 07, 2006: Message edited by: Eddy Lee Sin Ti ]
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Arunprasath,

Many of the people using Javaranch do not speak English as a first language.
Some rely on lanugage translation software to interpret the text on these pages. We ask that you do not use abbreviations when typing here. Use "you" instead of "u" and "you are" or "you're" instead of "ur".
Such abbreviations confound this software making it impossible for these people to read your answers.

Thank you for your understanding,
-The Bartender.
 
Pradeep bhatt
Ranch Hand
Posts: 8927
Firefox Browser Java Spring
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HTML SERVLET
POST- doPost()
GET- doGet(),doPost()


How can a doPost() method get called for HTTP GET.
 
Stan James
(instanceof Sidekick)
Ranch Hand
Posts: 8791
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I think it's pretty common to override doGet and doPost and have both call a common method like doMyThing. Unfortunately it says you're not thinking about the meaning of GET or POST (or PUT or DELETE) and designing with the meaning in mind.

For some neat ideas on this read up on Restful Architecture here or on the Wikipedia.
 
I agree. Here's the link: http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic