aspose file tools*
The moose likes Servlets and the fly likes request Vs Response object in web application Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "request Vs Response object in web application" Watch "request Vs Response object in web application" New topic
Author

request Vs Response object in web application

jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
In web application request is sent by client(browser) then response is constructed by server and send to client. But once request reach server side , some data put in request object. Why those data kept in request.
For ex: user send two integer a and b ,ask the server to add the two values and return its result. once the request reach the server ,both integer values should taken from request and result should be placed in response object or request object ???.

As per my understanding, request should not exist once it enter server and its data extracted .

Please suggest in this
Bauke Scholtz
Ranch Hand

Joined: Oct 08, 2006
Posts: 2458
The client won't get the request back. In the server side you can use the request object to access the initially entered request parameters and/or the request attributes (such as javabeans) in the JSP file.
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
1)so when the data is placed in response object.after data placed in response ,when it send to browser
2)if response object created then request object is destroyed???
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

Or, are you confused by the fact that you've seen data put into a request before being forwarded off to a JSP?


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
jacob deiter
Ranch Hand

Joined: Apr 02, 2008
Posts: 576
Here I add some code example,I add struts sample,






List of object created here and put into request. Why,instead i can code like this



please clear my confusion



Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

The purpose is so that the JSP will have access to the data after the forward.
Ankitt Gupta
Ranch Hand

Joined: Feb 19, 2009
Posts: 101
jacob deiter wrote:In web application request is sent by client(browser) then response is constructed by server and send to client. But once request reach server side , some data put in request object. Why those data kept in request.
For ex: user send two integer a and b ,ask the server to add the two values and return its result. once the request reach the server ,both integer values should taken from request and result should be placed in response object or request object ???.

As per my understanding, request should not exist once it enter server and its data extracted .

Please suggest in this



The client sends the request to the server.The container choose the corresponding servlet specified in the url.Then servlet calls its business logic i.e the model.After getting the result from the model the servlet adds it to the request object by setAttribute method. After that the view(JSP etc) gets the result from the request object by getAttribute method and then forwards it to container as a response.

Please correct me if i am wrong as i am also a starter
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61221
    
  66

That's all pretty close except for this part:
Ankitt Gupta wrote: and then forwards it to container as a response.

The term "forward" has a specific meaning within a web application and the response is not forwarded, and it is not sent to the container. Rather, the container returns the response to the client.
meehul Chopra
Greenhorn

Joined: Feb 23, 2009
Posts: 10
jacob deiter wrote:Here I add some code example,I add struts sample,






List of object created here and put into request. Why,instead i can code like this



please clear my confusion




Hi Jacob,

You can never set an attribute on a response object.
Now if you want to pass some information from the servlet to say a Jsp,you have two ways of doing that-->

1) Use a RequestDispatcher
In this case the transfer of the control happens at the server side.So the request is the same and thus you can set
the attribute in the request scope and get the attribute in the Jsp.

2) Use redirection
In this case the browser does the work that is generates a new request to the Jsp.
Hence setting and getting in the request scope wont work.
Then to transfer information you can say set and get attributes using session or ServletContext scope.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: request Vs Response object in web application