我在servlet中設置會話變量,並希望在javascript中訪問該變量。在javascript中讀會話變量?
ps = con.prepareStatement("select * from USERDETAILS where username=? and password=?");
ps.setString(1, username);
session.setAttribute("userName", username);
我在JavaScript函數中試過這些。但它不工作...
var name = ${userName};
var name = '<%= Session["userName"] %>';
的[訪問會話變量以JavaScript JSP裏面]可能重複(http://stackoverflow.com/questions/7241442/accessing-session-variables-in-javascript-inside- jsp) –
btw什麼是您使用的服務器端語言? – gnanz