Tuesday, May 28, 2024
 Popular · Latest · Hot · Upcoming
66
rated 0 times [  70] [ 4]  / answers: 1 / hits: 101122  / 11 Years ago, fri, august 2, 2013, 12:00:00

I am setting session variable in servlet and want to access that variable in javascript.



 ps = con.prepareStatement(select * from USERDETAILS where username=? and password=?);
ps.setString(1, username);
session.setAttribute(userName, username);


I tried these in javascript function. but it wasn't working...



var name = ${userName};
var name = '<%= Session[userName] %>';

More From » java

 Answers
23

Seems you should be able to use getAttribute():



var name = '<%= session.getAttribute(userName) %>';


Though, this depends on Java running through the file to replace the embedded <%= ... %>, which probably won't be the case in separate .js files.


[#76581] Thursday, August 1, 2013, 11 Years  [reply] [flag answer]
Only authorized users can answer the question. Please sign in first, or register a free account.
ibrahimgilbertoz

Total Points: 420
Total Questions: 112
Total Answers: 92

Location: Bonaire
Member since Sat, May 1, 2021
3 Years ago
;