1

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.

3 Answers 3

6

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 ();
Sign up to request clarification or add additional context in comments.

Comments

0

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 ?

Comments

-1
var session;
$.ajaxSetup({cache: false})
$.get('getsession.jsp', function (data) {
    session = data;
});

AND jsp will be:

<% response.getWriter().write(request.getAttribute("metricValues"));   %>

2 Comments

you may want to explain your answer
Just parse returned object into JSON in JavaScript.

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.