aspose file tools*
The moose likes JSP and the fly likes Adding Javascript global Variables to Http Request Session Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » JSP
Bookmark "Adding Javascript global Variables to Http Request Session" Watch "Adding Javascript global Variables to Http Request Session" New topic
Author

Adding Javascript global Variables to Http Request Session

Joe Urbanek
Greenhorn

Joined: Jan 31, 2005
Posts: 15
I have a JSP that includes the following javascript functions to generate a swap list. The Options are 2 collections, hostList and targetHostList which are retrieved from a database on the server and loaded into the request session. The User makes selections and these selecteds are stored in Global Javascript variable selectedOptions. How can I make the javascript variable selectedOptions accessable to the Servlet when it is posted?

Here is the code which I am trying to accomplish this with:
(Java Script Swap List):



Your assistance is greatly appreciated
Stefan Evans
Bartender

Joined: Jul 06, 2005
Posts: 1018
The only way to pass values to Java code would be via a request parameter.

Put a hidden field on the page, and populate it with a comma separated list of selected items.
Your Servlet code can then retrieve that String, parse it and determine the selected options.
Joe Urbanek
Greenhorn

Joined: Jan 31, 2005
Posts: 15
That worked for me, thank you.
 
Consider Paul's rocket mass heater.
 
subject: Adding Javascript global Variables to Http Request Session