This week's giveaway is in the Spring forum.
We're giving away four copies of REST with Spring (video course) and have Eugen Paraschiv on-line!
See this thread for details.
The moose likes Servlets and the fly likes Question on servlet Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of REST with Spring (video course) this week in the Spring forum!
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question on servlet" Watch "Question on servlet" New topic

Question on servlet

Grishma Dube
Ranch Hand

Joined: Jul 01, 2003
Posts: 275
Suppose i'm calling a servlet from jsp or html page. In that page, i'm specified method=post. But in servlet i've only doGet() and service() doPost() method. Will it throw any error or it will work fine?
Andrea Gazzarini
Ranch Hand

Joined: Sep 09, 2002
Posts: 125
If you override the service method and don't call the super.service(), this doesn't call the doPost() even if you request is a POST request!
if you implement only the doGet method, then you'll get an error, because the service method will try to locate a doPost() to forward the request.
Hope it helps.

Regards,<br />Andrea<br /> <br /><a href="" target="_blank" rel="nofollow">Andrea Gazzarini</a><br />Skype ID : gazzax72<br />Google Talk ID :<br /><a href="" target="_blank" rel="nofollow">My Blog</a>
Sainudheen Mydeen
Ranch Hand

Joined: Aug 18, 2003
Posts: 218
Hi Grishma Dube
You can try this.
Add a doPost method in your servlet as follows
public void doPost(HttpServletRequest req, HttpServletResponse res) throws ServletExcepion, IOException {
doGet(req, res); // calls your existing doGet method
I agree. Here's the link:
subject: Question on servlet
It's not a secret anymore!