How can you copy a JavaScript variable to a JSP session variable without using cookies?

Peter Wang

There are three things you have to do in order to make it to work.

1. You need a servlet to store the selected value of SELECT in session in the first place. If the SELECT list is static , just store the selectedIndex in the session.

2. On the same JSP where SELECT resides, you need put a server side code close to this

final HttpSession   curSession   = request.getSession( false );
  final String    selectedIndex  = (String)curSession.getValue(selectedIndexKeyName);
to pull the selectedIndex out of the session you put in the first place.

3. write onLoad method for JSP where SELECT resides

<body onLoad='initPage ()'>
where intiPage() is a JavaScript function that will set SELECT list selectedIndex to previous value.
document.frmCity.selCity.selectedIndex = %= selectedIndex %>