<%String m="1"; %>
In my JSP file
<select name ="test">
<option value="2"> 2 </option>
<option value="3"> 3 </option>
<option value="4"> 4 </option>
</select>
Based on what is chosen on selection list I want to assign value to the variable m. What is the best approach to do this. Thanks.
Put it in a HTML
<form>and add a submit button.This way the variable will be sent as HTTP request parameter with the name of the input element as parameter name. You can then get it as follows:
Note that postprocessing a form submit is normally to be done in a servlet, not a JSP.