Win a copy of Re-engineering Legacy Software this week in the Refactoring forum
or Docker in Action in the Cloud/Virtualization forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Question on servlet

 
Grishma Dube
Ranch Hand
Posts: 275
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 125
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic