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
posted
0
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.
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???
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
posted
0
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
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
posted
0
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.