my dog learned polymorphism*
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
JavaRanch » Java Forums » Java » Servlets
Bookmark "Question on servlet" Watch "Question on servlet" New topic
Author

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() method..no 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="http://www.linkedin.com/in/andreagazzarini" target="_blank" rel="nofollow">Andrea Gazzarini</a><br />Skype ID : gazzax72<br />Google Talk ID : a.gazzarini@gmail.com<br /><a href="http://www.andreagazzarini.blogspot.com" 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
}
Thanks
Sainudheen
 
Consider Paul's rocket mass heater.
 
subject: Question on servlet
 
Similar Threads
Invoke a method through URL
WML To Servlet
Do I need to use ! for declarations?
instance variables of the servlet
doGet() doPost() doPut() Which one??