Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

doPost And DoGet() method question  RSS feed

 
Sumukh Deshpande
Ranch Hand
Posts: 87
Firefox Browser IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am trying to call doGet of Servlet_B from doPost of Servlet_A.

But I see a message sating doPost() is not supported. The code is as follows:




Is it that there is only one to one correspondence between methods of Servlets i.e. doPost() can call only doPost() and doGet() can only call doGet().

Thanks in advance.


 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Within one request, yes.

The request method will stay the same for the duration of that request.
Why are you trying to handle a request in the doGet method if the request was the result of a post request?
 
Sumukh Deshpande
Ranch Hand
Posts: 87
Firefox Browser IntelliJ IDE
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Why are you trying to handle a request in the doGet method if the request was the result of a post request?

I was just trying to see what could happen. No specific intention.


Within one request, yes.
The request method will stay the same for the duration of that request.


Is it a HTTP protocol limitation or this constraint is enforced to avoid some problem?

Thanks.


 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The HTTP protocol doesn't limit what happens inside an app server.

http://faq.javaranch.com/java/FileUpload

It's the way servlets work. The interface defines a method for each type of HTTP request (GET, POST, HEAD, PUT, etc..).
It also allows you to chain servlets and JSPs.

Maybe a better question would be: Why wouldn't you want this enforced? If a browser makes a get request and your first servlet passes the request to another via a dispatcher, why wouldn't you want that request to go to the second servlet's doPost method?
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!