ابدأ بالتواصل مع الأشخاص وتبادل معارفك المهنية

أنشئ حسابًا أو سجّل الدخول للانضمام إلى مجتمعك المهني.

متابعة

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

user-image
تم إضافة السؤال من قبل Yasmeen Husam , Web Developer , Al Fahid Systems
تاريخ النشر: 2019/01/30
Parmod Prajapati
من قبل Parmod Prajapati , Java Developer , Indianmesh Pvt. Ltd.

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

Ammar Ayaz
من قبل 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 %>

 

المزيد من الأسئلة المماثلة