Win a copy of The Little Book of Impediments (e-book only) this week in the Agile and Other Processes forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Create HttpResponse 's object

 
ratan lal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Could you tell me can i create HttpResponse's object or server can create when service method will call. if yes then how.


 
Ulf Dittmer
Rancher
Posts: 42969
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The server creates an object that implements the HttpServletResponse interface and hands it to the servlet code in the doGet, doPost etc. methods. Are you asking how your code can create such an object? If so, for what purpose?
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HttpServletRequest is an interface and needs to have an implementing class. The server catches the request and has its own implementation, and creates and instance and puts the information in that instance before passing it to you.
In practice you should never need to know the implementing class or need to create one yourself, although there is the HttpServletRequestWrapper typically used in filters
 
David O'Meara
Rancher
Posts: 13459
Android Eclipse IDE Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
switch everything I said 'Request' for 'Response'
 
reddy sekhar
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my knowledge, the request and response object used to create when ever new request come from client to Server.

But the implementation of these HttpServletRequest and HttpServletResponse interfaces are provided by service providers...like Tomcat,weblogic..etc.

So when ever request comes from client, the web server receives the request and makes the these objects.

I hope this may help you.

thanks
/Reddy.
 
ratan lal
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Actually i want to print out message in another method that is other than doPost or doGet method. For that i think i have to create HttpResponse object so that i can call it's getWriter method to get PrintWriter in that method.
 
Bear Bibeault
Author and ninkuma
Marshal
Pie
Posts: 65335
97
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I'm not sure what you are trying to do, as you are not explaining it well, but whatever it is, it does not require you to create your own response. You never have to do that.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13077
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For that i think i have to create HttpResponse object so that i can call it's getWriter method to get PrintWriter in that method.


In your doGet or doPost you can call getWriter to the the PrintWriter and then pass that to methods which need it.

It is a bad design to pass around the request and response references when you can easily get the important contents as instances of Java classes which are NOT tied to the servlet API. By using standard Java classes you can test outside the servlet environment, much simpler and faster.

- for example

from a request you can getParameterMap - returning a java.util.Map
from a response you can getOuputStream or getWriter - both return objects you can treat as standard library objects for testing.

Bill
 
azhar jodatti
Greenhorn
Posts: 12
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
As per my knowlege there is no way exist for creating our own request and response object..

it wil give by the container......

if you want to use those object in other methods then just pass those objects as argument..

as per as me is concered this is only way i think...


suggest if there is other way
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic