I am storing a variable through java in session by following mand :
request.setAttribute("metricValues", metricDataList);
Now I am trying to access this session object through a java script which is stored outside the JSP.
I am storing a variable through java in session by following mand :
request.setAttribute("metricValues", metricDataList);
Now I am trying to access this session object through a java script which is stored outside the JSP.
Share Improve this question edited Oct 7, 2014 at 8:26 fredtantini 16.6k8 gold badges51 silver badges58 bronze badges asked Oct 7, 2014 at 8:16 Govind Singh RawatGovind Singh Rawat 111 silver badge2 bronze badges3 Answers
Reset to default 6On your JSP create a hidden HTML element with this value.
When you body has loaded use javascript or jquery to read this value.
Java
session.setAttribute("metricValues", metricDataList); // you state session
JSP
<input id='mv' type='hidden' value='${sessionScope.metricValues}'/> // you state session variable
JS
$(document).ready(function(){
var mv = $('#mv').val ();
You could add this values in http header on server side and read them with javascript on client side ? I mean you could do that in bean or in phaselistener ?
var session;
$.ajaxSetup({cache: false})
$.get('getsession.jsp', function (data) {
session = data;
});
AND jsp will be:
<% response.getWriter().write(request.getAttribute("metricValues")); %>