This week's book giveaway is in the OCPJP forum. We're giving away four copies of OCA/OCP Java SE 7 Programmer I & II Study Guide and have Kathy Sierra & Bert Bates on-line! See this thread for details.
Hi All I was not sure if to put this in struts forum or servlet but query was more related to request/response therefore I am posting it here I have an Action class which needs to delegate control to another action class on some condition I in execute method of this class I was trying to set responseHeader with same attribute,value pair and in other Action I tried to retrieve same attribute and it came out as null (I was not using any redirect) Since request was not lost I am wondering If I used correct function for sending some name,value pair in response from one class and trying to retrive it from other action class
Thanks in advance :roll:
SCJP,SCWCD,SCBCD<br />If Opportunity doesn't knock then build the door
If you are forwarding the request from action1 to action2, just put the data in the HttpServletReqeust though I bet there is a more "struts" way of doing such a thing. [ August 15, 2006: Message edited by: Gregg Bolinger ]
Originally posted by Gaurav Chikara: But still this will remain mystery for me as why even on putting values on response header in one action class and trying to retrive it through request object in other one didn't work
So did you really expect that the client (the browser) would automatically copy those response headers and then send them as request headers with its next request? That isn't how it works.
But still this will remain mystery for me as why even on putting values on response header in one action class and trying to retrive it through request object in other one didn't work
Think of headers as a low level HTTP communication issue. We, the application developers, should not normally need to concern ourselves with them (any more than we should need to concern ourselves with how TCP/IP works).
The servlet spec gives you plenty of ways to pass data from one component to another. Any good tutorial will cover them and provide guidance for picking the best one for your given situation.
save some prospective performance issue by not using session
Where do these weird ideas come from If you understood all the work that the servlet engine puts into creating the request and response objects for every single request you would realise that creating a session object takes an insignificant portion of total response time. Bill
Joined: Jun 09, 2000
Thanks a lot all of you for clarifying my confusion You all are great
I have an Action class which needs to delegate control to another action class on some condition
Since you need to delegate control on some condition, and the request/response cycle needs to present only for that condition it is better to use request attributes than session attributes.
I was trying to set responseHeader with same attribute
Dude Headers are used to communicate with the client(browser) and NOT intra-application.
Say you want to tell the browser to stop caching the pages you do that via headers.
Joined: Jun 09, 2000
it is better to use request attributes than session attributes.
I didnt used request attributes because they are used for pulling the data and my condition had a requirement that I have to push the data from one action and pull it from other one and thats why I was wondering how request/response communication takes place
I didnt used request attributes because they are used for pulling the data and my condition had a requirement that I have to push the data
I have no idea where you got this idea, or even what you mean by "push" and "pull". Either scope can be used to pass data from one resource to a forwarded resource, and request scope is preferred when the data does not need to persist for the entire session.
Joined: Jun 09, 2000
I have no idea where you got this idea,
I was talking about interface HttpServletRequest and not the request attribute.It seems I was misunderstood as HttpServletRequest doesn't have any method for putting the data it only has getters
I hope that I am clear now [ August 19, 2006: Message edited by: Gaurav Chikara ]