• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

How can I access JSP variable value in one jsp from adifferent jsp file

 
Chiran Mathur
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
How can I access JSP variable value in one jsp from a different jsp file?
 
Sudd Ghosh
Ranch Hand
Posts: 191
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
This is my take on this:
With static inclusion, using the include directive, both the original and the included page become a single translation unit. So variables get visible, like in a normal program flow in a single jsp file.
With dynamic/request-time inclusion, using the include action, the requst parameters get passed to the included page without doing anything special.It can also pass other variables using the <jsp aram ../> nested tag.
 
vivek sivakumar
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
well one solution is for ex lets say the variable called var 1 is present in a file called A.jsp and u want to access it in B.jsp then one possible solution is that in A.jsp use include directive <%@ include file ="B.jsp" %> , when translating this jsp the whole part of A.jsp and B.jsp will be combined and translated so ur B.jsp will have access to elements in A.jsp also.
This is also called as Static Inclusion .
Well it could also be done thro dynamic inclusion .
hope this helps.
 
Dharmin Desai
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear friends,
Can't we use ServletContext and Session for sharing variable in jsp file also ?
Dharmin
 
Rishi Yagnik
Ranch Hand
Posts: 84
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
ya we can make use of that implicit Objects i.e appliaction,session and request for single request and pageContext also.
correct me if i am wrong.......
Rishi
 
vivek sivakumar
Ranch Hand
Posts: 187
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
but the question is about " How can I access JSP variable value in one jsp from adifferent jsp file" which denotes just plain variables(taking it for granted) , where as servletcontext talks about objects and variables !!!
[ January 23, 2003: Message edited by: vivek sivakumar ]
 
Dharmin Desai
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Dear vivek,
I think, u r going in a wrong way. There is no difference between plain variables and Objects.
Every variable r in turn an object.
And any object u can bind with context or session.
regards, Dharmin
 
Chiran Mathur
Ranch Hand
Posts: 63
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Yes, this is what I want to do:
test1.jsp
int x=0;
int y=0;
Need x and y to be accessed in test2.jsp

Based on certain conditions in the file, I want to foward to test2.jsp and access the values of variable x and y there. I do not want to get it from the session and at the same time I do not want to do a include in test1.jsp. Is it possible?
 
Dharmin Desai
Ranch Hand
Posts: 81
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use request.setAttribute() and request.getAttribute() methods to set and get attributes.
They would be even available when u redirect yr request to the next jsp page.
Best regards,
Dharmin
 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic