Want to protect your cyber security and still get fast solutions? Ask a secure question today.Go Premium

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 167
  • Last Modified:

using variables in multiple pages

If I have declared my variables in a page called test1.jsp, I want to print out these variables in a page called test2.jsp. Is this possible? Please help!!
0
VbMonk
Asked:
VbMonk
  • 2
  • 2
1 Solution
 
ldbkuttyCommented:
Use "session".

in page1.jsp:

<%
   String var = "something";
   session.setAttribute( "theVar", var );
%>

and in other pages you can retrieve it with:

<%=session.getAttribute("theVar")%>
0
 
kiranhkCommented:
you can use request also

in page1.jsp:

<%
   String var = "something";
   request.setAttribute( "theVar", var );
%>

and in other pages you can retrieve it with:

<%=request.getAttribute("theVar")%>

or if you can have hidden field inside the form of your first jsp which will take the from from these defined variables then when the form is posted to the second jsp you will ge able to retrieve the values using
request.getParameter(Nameof your hidden field)
0
 
ldbkuttyCommented:
but data stored in "request" will not be available in all pages, its just the sessions taht can do.
0
 
kiranhkCommented:
>>> I want to print out these variables in a page called test2.jsp
the req is only for printing in the next page!!!!!
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 2
  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now