Communiquez avec les autres et partagez vos connaissances professionnelles

Inscrivez-vous ou connectez-vous pour rejoindre votre communauté professionnelle.

Suivre

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

user-image
Question ajoutée par Yasmeen Husam , Web Developer , Al Fahid Systems
Date de publication: 2019/01/30
Parmod Prajapati
par Parmod Prajapati , Java Developer , Indianmesh Pvt. Ltd.

You may use ajax, when you want to save variable value into session

Ammar Ayaz
par Ammar Ayaz , Senior Web Developer , Instacommerce

JSPs run at the server, while JavaScript runs at the client - never the twain shall meet. 

 

The JSP already knows the URL of the page it's generating - what else are you looking for?But might be this can help you:-

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

 

A. 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.

 

B. 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.

 

C. 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 %>

 

More Questions Like This