• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

request Vs Response object in web application

 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 2458
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Or, are you confused by the fact that you've seen data put into a request before being forwarded off to a JSP?
 
jacob deiter
Ranch Hand
Posts: 584
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The purpose is so that the JSP will have access to the data after the forward.
 
Ankitt Gupta
Ranch Hand
Posts: 101
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Pie
Posts: 64830
86
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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
Posts: 10
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
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.
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic