aspose file tools*
The moose likes Web Component Certification (SCWCD/OCPJWCD) and the fly likes How can I access JSP variable value in one jsp from adifferent jsp file Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Soft Skills this week in the Jobs Discussion forum!
JavaRanch » Java Forums » Certification » Web Component Certification (SCWCD/OCPJWCD)
Bookmark "How can I access JSP variable value in one jsp from adifferent jsp file" Watch "How can I access JSP variable value in one jsp from adifferent jsp file" New topic
Author

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

Chiran Mathur
Ranch Hand

Joined: Feb 07, 2001
Posts: 63
How can I access JSP variable value in one jsp from a different jsp file?
Sudd Ghosh
Ranch Hand

Joined: Oct 23, 2002
Posts: 187
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.


SCJP 1.4, SCWCD, SCBCD 1.3
vivek sivakumar
Ranch Hand

Joined: Aug 09, 2001
Posts: 187
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.


SCJP, SCWD <br />A farmer learns more from a bad harvest than a good one.
Dharmin Desai
Ranch Hand

Joined: Feb 28, 2002
Posts: 81
Dear friends,
Can't we use ServletContext and Session for sharing variable in jsp file also ?
Dharmin


SCJP2 (93%),SCWCD(88%)<br />-------------------------------<br />Never under estimate yr self, just represent yr profile in proper manner.
Rishi Yagnik
Ranch Hand

Joined: Jan 04, 2001
Posts: 84
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

Joined: Aug 09, 2001
Posts: 187
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

Joined: Feb 28, 2002
Posts: 81
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

Joined: Feb 07, 2001
Posts: 63
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

Joined: Feb 28, 2002
Posts: 81
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
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How can I access JSP variable value in one jsp from adifferent jsp file