JSP Session in JavaScript variable problem

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • buntyindia
    New Member
    • Jun 2007
    • 101

    #1

    JSP Session in JavaScript variable problem

    Hi,


    I have a session variable msgSize that is being set by a Java file in the session.
    Code:
    aRequest.getSession().setAttribute("msgSize", msgSize);
    It's value is variable depends on record count of recordset.


    In JSP page where I have to assign it's value to a javascript variable. I am doing this a s follows. I have done this in the JSP file.

    [PHP]<script type="text/javascript" >
    <!--
    function getVal()
    {
    m=${msgSize};
    }
    -->
    </script>[/PHP]

    First Problem is I am unable to get this value inside a External JS file. It throws error but inside jsp it is working. How can i use this inside External JS?

    Second problem is once the above code executed value never refreshed to new value?
    Means first time it executed it get value 200 next time again i executed the code the real recordset is 105 but still displaying 200. But when I restart the server next time it takes value 105 by itself....

    How I tacckle this problem.?


    Regards,
  • buntyindia
    New Member
    • Jun 2007
    • 101

    #2
    problem is I am not refreshing the whole page, refreshing the partial page using ajax call that's why not getting the session new value...

    any suggestions ?

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by buntyindia
      First Problem is I am unable to get this value inside a External JS file. It throws error but inside jsp it is working. How can i use this inside External JS?

      Second problem is once the above code executed value never refreshed to new value?
      You won't be able to use this in an external JS file because it's JavaScript and not JSP. You could try using JSP to render JavaScript output and link to it.

      In your JSP code that gets called using Ajax, do you output the session variable and how are you attempting to get the value? Show your code.

      Comment

      Working...