I am storing a variable through java in session by following command :
request.setAttribute("metricValues", metricDataList);
Now I am trying to access this session object through a java script which is stored outside the JSP.
On 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 ();
var session;
$.ajaxSetup({cache: false})
$.get('getsession.jsp', function (data) {
session = data;
});
AND jsp will be:
<% response.getWriter().write(request.getAttribute("metricValues")); %>