Search code examples
jspscriptletstruts1

How to retrieve request scope value in jsp with struts1 tags?


Below is how I am setting my value to request scope. And not able to retrieve in java script alert, need some one help.

`request. set Attribute ("token", token);`

I am using like this <bean:parameter name="token"/>

But no luck..!!!


Solution

  • You can add the following code in head tag.

    This code takes the token value from the request and sets it to a local variable.

    <%
       String token = request.getAttribute("token").toString();                     
    %>      
    

    This code takes the value from the local variable and sets it to a javascript variable.

    <script type="text/javascript">   
        var tokenValue =  "<%=token%>";
        alert(tokenValue);  
    </script>