Win a copy of The Java Performance Companion this week in the Performance forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Why servlet has to reload the content after invoking doPost or DoGet

 
Ken Flor
Ranch Hand
Posts: 34
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi All,

I am very puzzled. Why Servlet must reload the content of the response when I call doGet/doPost after submitting my form.

I just want to do some logic in the doPost after submitting my form and to return the original content response without doing anything else. But i must do PrintWriter to output the same content again.


Why is that so?
Any way to return the original content.

Please help me.

Servlet is driving me crazy.
[ September 12, 2006: Message edited by: Bear Bibeault ]
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It isn't really the Servlet's fault, it's the transport mechanism. Servlets (mostly) talk HTTP, and HTTP says you must have a request and a response. You can't have a request without a response and you can't have a response without a request. The default for browsers is to send the request and then display the response on the page, so if you want to have the same page displayed you need to send the same page as the response.

The alternative is to use something different like AJAX (ie communication via JavaScript) to talk to the servlet so that you don't get the browser to manage the request/response but manage it yourself.

Dave
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by David O'Meara:

The alternative is to use something different like AJAX (ie communication via JavaScript) to talk to the servlet so that you don't get the browser to manage the request/response but manage it yourself.

Dave


And.... even if you do this, the server side of the application will still return one response per request.
This is how HTTP works.
 
Scott Duncan
Ranch Hand
Posts: 365
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
But i must do PrintWriter to output the same content again.


Ideally, you would not want to use the servlet to output the content at all. You should use a JSP for this that submits to a servlet. The servlet performs some logic and forwards back to the JSP.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic