GeeCON Prague 2014*
The moose likes Servlets and the fly likes Request /Response issue Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


JavaRanch » Java Forums » Java » Servlets
Bookmark "Request /Response issue" Watch "Request /Response issue" New topic
Author

Request /Response issue

Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
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
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

Why are you trying to pass name/value pairs between different parts of your application using HTTP headers?


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
I was considering not to put them in session and save some prospective performance issue by not using session .
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

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 ]

GenRocket - Experts at Building Test Data
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
Thanks for your reply Greg
I finally ended up using session only as HttpServletRequest didn't seemed to have any method where we can put our data.

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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by Gaurav Chikara:

I finally ended up using session only as HttpServletRequest didn't seemed to have any method where we can put our data.


You mustn't have looked very hard.


[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Paul Clapham
Bartender

Joined: Oct 14, 2005
Posts: 18570
    
    8

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.
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

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


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.
William Brogden
Author and all-around good cowpoke
Rancher

Joined: Mar 22, 2000
Posts: 12792
    
    5
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
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
Thanks a lot all of you for clarifying my confusion
You all are great
Richard Green
Ranch Hand

Joined: Aug 25, 2005
Posts: 536
If Opportunity doesn't knock then build the door

I like it


MCSD, SCJP, SCWCD, SCBCD, SCJD (in progress - URLybird 1.2.1)
rama murthy
Ranch Hand

Joined: Jan 13, 2006
Posts: 82

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.
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
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
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by Gaurav Chikara:

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.
Gaurav Chikara
Ranch Hand

Joined: Jun 09, 2000
Posts: 410
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 ]
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61315
    
  66

Originally posted by Gaurav Chikara:
as HttpServletRequest doesn't have any method for putting the data it only has getters


I think that you had better take a closer look.


I hope that I am clear now


Not really as it still seems you have some misconceptions as to how to use the variable scopes.
Gregg Bolinger
GenRocket Founder
Ranch Hand

Joined: Jul 11, 2001
Posts: 15299
    
    6

ServletRequest

HttpServletRequest doesn't have a setter, but it's parent interface does.
 
GeeCON Prague 2014
 
subject: Request /Response issue