• Post Reply Bookmark Topic Watch Topic
  • New Topic

Forwarding a variable with request scope

 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
hello friends,
I have a variable x with request scope. now i am in a situation where if i traverse to page A x should not be visible and if i travel to page B x should be visible. can anyone help me out how this is possible.
thanks
shekar
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Are you forwarding tp page A and then Page B?
 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It can be to any page but it will be dynamic. it will depend on a variable and some condition
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I am still not clear.

Remove the attribute from request scope and store it in session scope. Whenever required pull it from session ans store it in request.
 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
i am not clear as well as what you need to answer my question. firstly let me make you clear that the scope hierarchy i feel is
page
request
session and
application/context.
now I have put a variable(let us say x) in request scope in page A and i am supposed to have it in request scope. From A i can go either to page B or page C. but it i go to page B then i can see that variable i.e. i can just say request.getparameter() but if i go to page C i should not be able to get the current scope variables. i hope this is clear.
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
now I have put a variable(let us say x) in request scope in page A and i am supposed to have it in request scope. From A i can go either to page B or page C. but it i go to page B then i can see that variable i.e. i can just say request.getparameter() but if i go to page C i should not be able to get the current scope variables.


I guess you are talking about request attribute and not request parameters.
You can remove the request parameters from the request scope by calling
request.removeAttribute() when yopu forward to page C.
 
Chandra Bairi
Ranch Hand
Posts: 152
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I asked one of my friend and he said if we have to see a variable from request scope then it has to be jsp:forward and if we want to isolate it then it has to be redirect. is that true?
 
Sainudheen Mydeen
Ranch Hand
Posts: 218
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Hi
In A, set the attribute in request scope only when are forwarding to B. Probably you have a condition that decide to forward to B or C. Set the request attribute inside the condition.
---------------
Sainudheen
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Chandra Bairi:
I asked one of my friend and he said if we have to see a variable from request scope then it has to be jsp:forward and if we want to isolate it then it has to be redirect. is that true?

If you redirect all request attributes and parameters are lost.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!