File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Setting a JavaScript Variable to Session

 
Divya Chandrasekhar
Greenhorn
Posts: 21
Chrome Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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>

 
bhanu chowdary
Ranch Hand
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • 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
Chrome Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
the alert prints the value "Divya"... checked this
 
bhanu chowdary
Ranch Hand
Posts: 256
  • 0
  • Mark post as helpful
  • send pies
  • 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
Chrome Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • 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
  • 0
  • Mark post as helpful
  • send pies
  • 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
Chrome Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks bhanu, will try it out and let you know...
 
Divya Chandrasekhar
Greenhorn
Posts: 21
Chrome Java Oracle
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
No luck
Any help will be appreciated!
 
Hemant Thard
Ranch Hand
Posts: 122
  • 0
  • Mark post as helpful
  • send pies
  • 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.


 
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic