facebook

Access session variable created in java code in Javascript

  1. MyEclipse IDE
  2.  > 
  3. Java EE Development (EJB, JSP, Struts, XDoclet, etc.)
Viewing 4 posts - 1 through 4 (of 4 total)
  • Author
    Posts
  • #291315 Reply

    Pradeep_J
    Member

    Hi,

    I am creating a session variable in java..

    now i want to access the same variable from my code of java script to perform some task….

    is it possible?

    kindly brief with some example.

    #291316 Reply

    Pradeep_J
    Member

    Hi,

    I am creating a session variable in java..

    now i want to access the same variable from my code of java script to perform some task….

    is it possible?

    kindly brief with some example.

    #291379 Reply

    rmcvay
    Member

    You would have to use a Java scriptlet or custom tag to retrieve the value from the session and assign it to a Javascript variable or form input value.

    <script type=”text/javascript”>
    var sessionId = <%= session.getId() %>
    </script>

    Of course you’d use session.getAttribute(“varname”) to get your object (not “variable”) from the session and you’d have to deal with casting it to its type and getting the value of the specific member you’re looking for.

    #291381 Reply

    rmcvay
    Member

    In the head:
    <script type=”text/javascript”>
    var sessionId = “<%= session.getId() %>”
    </script>

    In the body:
    <p><script type=”text/javascript”>document.write(“Session ID: “, sessionId);</script></p>

Viewing 4 posts - 1 through 4 (of 4 total)
Reply To: Access session variable created in java code in Javascript

You must be logged in to post in the forum log in