• 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

Setting a JavaScript Variable to Session

 
Greenhorn
Posts: 21
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi All,

I have an issue with setting a JavaScript variable to session. This is a string and I need to retrieve this in my Action Class and process further. I am using Struts 1.1.
I have tried setting this variable as a hidden variable however, it doesn't reach the Action Class - I get a null value.

Any suggestions on what I would need to do?

Here's the gist of what I am trying to do:

JSP:
<html>
<body>
<input type="hidden" name="userInfo" />
<input type="submit" onclick="submit();" value="Submit">
<input type="submit" onclick="cancel();" value="Cancel">

<form>
....
....
....
//make a call to foo()
</form>
<script>
function foo() {
var bar = "Divya";
document.getElementsByTagName("userInfo").value = bar;
}
</script>
</body>
</html>

 
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Just to be sure, Did you have the variable"userInfo" in the actionform?? And how are you accessing this value in the action class??
Please put an alert below the code and see what is being printed.
 
Divya Chandrasekhar
Greenhorn
Posts: 21
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
the alert prints the value "Divya"... checked this
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

bhanu chowdary wrote: Did you have the variable"userInfo" in the actionform?? And how are you accessing this value in the action class??


You didn't answer these questions
 
Divya Chandrasekhar
Greenhorn
Posts: 21
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
My bad
To answer your questions:
1. I have a variable userInfo in the action form
2. I am accessing the value by doing a String str = request.getParameter("userInfo");
 
bhanu chowdary
Ranch Hand
Posts: 256
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Its been a while since I have worked on struts. I remember encountering the same issue once.
Could you please try it with <html:hidden> tag instead of <input type=hidden>?
I don't have my workspace setup to work with struts now. But its worth giving a try

This should be inside the form tag
 
Divya Chandrasekhar
Greenhorn
Posts: 21
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks bhanu, will try it out and let you know...
 
Divya Chandrasekhar
Greenhorn
Posts: 21
Oracle Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
No luck
Any help will be appreciated!
 
Ranch Hand
Posts: 122
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Divya,

My suggestion will be to try to convert your post request to get and see if that parameter is appended to your URL.

if not, there is only one logical reason that your parameter "userinfo" is not a part of the form that is submitted.


 
Hang a left on main. Then read this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic