how to pass the session value jsp to javascript

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • shyamsunder
    New Member
    • Jun 2007
    • 2

    #1

    how to pass the session value jsp to javascript

    i hava to write like this but iam getting the null value .




    <%String brokerCDOP=(Str ing)session.get Attribute("brok erCDOP");
    out.print(broke rCDOP);%>

    <script language="javas cript">
    var alertValue = '<%=brokerCDOP %>';
    </script>
  • r035198x
    MVP
    • Sep 2006
    • 13225

    #2
    Originally posted by shyamsunder
    i hava to write like this but iam getting the null value .




    <%String brokerCDOP=(Str ing)session.get Attribute("brok erCDOP");
    out.print(broke rCDOP);%>

    <script language="javas cript">
    var alertValue = '<%=brokerCDOP %>';
    </script>
    Use a hiiden input to pass the Java value to javascript.
    [HTML]<input type ="hidden" value="<%=broke rCDOP %>" name ="myVal"> [/HTML]

    Then in the Javascript you can get the value using [HTML]document.form['formName'].myVal.value;[/HTML]

    Comment

    • dmjpro
      Top Contributor
      • Jan 2007
      • 2476

      #3
      Originally posted by shyamsunder
      i hava to write like this but iam getting the null value .




      <%String brokerCDOP=(Str ing)session.get Attribute("brok erCDOP");
      out.print(broke rCDOP);%>

      <script language="javas cript">
      var alertValue = '<%=brokerCDOP %>';
      </script>
      brokerCDOP, this value u r getting null?
      If that then there is no attribute bound with the name brokerCDOP.
      I think u r right with ur code.
      What acoder syas that is also right.
      But ur code is more effective.
      If we can access the value using ur technique then there is no need to create an extra hidden field.Right?
      Plz inform me what u understood.

      Kind regards,
      Dmjpro.

      Comment

      Working...