• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

Passing values between pages

 
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
How can I pass values between pages? For example...
If I have a hidden variable and I click on a link how can I get that hidden variable value to be passed.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
mrsmithq, There are a couple of ways to pass a variable from 1 page to another. Here are 3 ways that I know of.
- QueryStrings
You would change your link so that the hidden variable is in the link. This is only good if you don't care if people see the value. If you want the value to remain invisible don't select this.
- Forms
This requires a little javascript that submits a form when you click on the link. This means that all values of the fields in this form are passed to the next page. So your hidden field gets sent to the other page.
- Session Variables
This stores the information in a variable for the duration of your WWW session. It can then be accessed from the next page as well as others.
Let me know which you would like to know more about and i can paste some code examples.
Joey
 
mrsmithq
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Well, here is what I am trying to set a variable to: <jetspeed:info requestedInfo="Screen" />
I would say session, but either option is fine.
Thanks
 
Joey Duguay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
This is how you create a set a variable in your session.
HttpSession aServletSession = request.getSession(true);
// timeout for the session. Default is 30 minutes i beleive
aServletSession.setMaxInactiveInterval(timeout); (optional)
// Se the variable
aServletSession.setAttribute("VariableName", strValue);
Then if you wish to get the variable in another page you do the following.
// this one is false because you just want to make sure there is a session. if this returns null the user doesn't havea session.
HttpSession aServletSession = request.getSession(false);
// Get the variable's value
String value = aServletSession.getAttribute("VariableName");
I think that is all you will need. You can put different type of data in these session variables. Objects, int, String..... I used it for Vectors. So it's flexible.
Joey
 
mrsmithq
Greenhorn
Posts: 8
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

<jetspeed:info requestedInfo="Screen" />
This is a string but it just wot work. When I try to use the baove to set it to a hidden variable it works though...

<input type="hidden" name="current_screen"
value="<jetspeed:info requestedInfo="Screen" />">
so how can I use it to do something else?
 
Joey Duguay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hello,
I'm not too familiar with JSP tags but you could use the form method. As you mentioned, you can set a hidden field to the value you wish. All you would need to do is surround the fields you wish to pass to the next field in form tags. I.e.
<FORM NAME="main" action="next.jsp">
<input type="hidden" name="current_screen" value="<jetspeed:info requestedInfo="Screen" />">
</FORM>
Then your link would look something like.
<a href='javascript:main.submit();'>
This would submit the main form and pass all the fields in this form to JSP page you have in the action. Then you just need to get the value from the querystring.
String tempValue = request.getParameter( "current_screen" );
Joey
 
Joey Duguay
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I forgot to mention you might want to use method=POST for the form.
<FORM NAME="main" method=POST action="next.jsp">
<input type="hidden" name="current_screen" value="<jetspeed:info requestedInfo="Screen" />">
</FORM>
Joey
 
With a little knowledge, a cast iron skillet is non-stick and lasts a lifetime.
reply
    Bookmark Topic Watch Topic
  • New Topic