Passing a variable from Scriptlets to Javascript.

后端 未结 2 771
无人及你
无人及你 2021-01-22 09:12

I have this code snippet ::



        
2条回答
  •  北荒
    北荒 (楼主)
    2021-01-22 09:49

    When you need value of variable temp1 inside gotoa() do the following:

    <%  String temp1; // Store value in temp1 variable for later use
        PopulateTextbox obj = new PopulateTextbox(); 
        temp1 = obj.method();
    %>
    
    
    

    First you assign the value to variable temp1. And then you Render your JSP with a Hidden Input component with value=temp1 by using scriptlet. If you want to verify, just View the Source of generated HTML and you should see the value of input hidden equal to the variable.

    When the form is submitted the value of hiddenTemp1 will be available in Request. If you intend to change the value of this hidden component, you can set the value back in the component.

提交回复
热议问题