aspose file tools*
The moose likes Servlets and the fly likes why doPost() of HttpServlet commits response? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "why doPost() of HttpServlet commits response?" Watch "why doPost() of HttpServlet commits response?" New topic
Author

why doPost() of HttpServlet commits response?

ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830


Here I am getting IllegalStateException here. I can guess, it is because doPost() of HttpServlet is already commiting response. But why it is so?

Thanks.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Why are you calling super.doPost()?
ankur rathi
Ranch Hand

Joined: Oct 11, 2004
Posts: 3830
Originally posted by David O'Meara:
Why are you calling super.doPost()?


Actually, WSAD generated it automatically, and because I was not knowing the insides, so I kept it as it is...

My doubt is, why it commits the response???

Thanks.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

If your servlet doesn't implement doPost and someone makes a post request to it, the container will let them know that this type of request is not supported by throwing a servletException with a meaningful message.

To change this behaviour, you override doPost and add your own code.
There is really no point in calling super.doPost.
[ December 01, 2005: Message edited by: Ben Souther ]

Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Withour going into the details, I was also thinking what Ben said.

There is really no point in calling super.doPost.

Well there can be, but only if you know why you're doing it. For example we had a abstract Servlet once which did some generic processing, but if I remember correctly we designed it a bit diferently so it wasn't as good a story as I'd hoped
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

I should have qualified that.
There's almost no reason to call super.doPost.
David O'Meara
Rancher

Joined: Mar 06, 2001
Posts: 13459

Vishnu Prakash
Ranch Hand

Joined: Nov 15, 2004
Posts: 1026
You got to override the doPost method with public access modifier.


Servlet Spec 2.4/ Jsp Spec 2.0/ JSTL Spec 1.1 - JSTL Tag Documentation
 
jQuery in Action, 2nd edition
 
subject: why doPost() of HttpServlet commits response?