我想使用 scriptlet 在选择标记中选择一个值,但它不起作用。 我怎样才能实现这个目标?
提前致谢。
<%int number=2;%>
<br><br>Matricula:
<select id="mat" name="mat" >
<option<%if(number==1){%>selected<%}%> >
01</option>
<option<%if(number==2){%>selected<%}%> >
02</option>
<option<%if(number==3){%>selected<%}%> >
03</option>
<option<%if(number==4){%>selected<%}%> >
04</option>
</select>
最佳答案
您需要在选项
和所选
之间添加空格
<%int number=2;%>
<br><br>Matricula:
<select id="mat" name="mat" >
<option <%if(number==1){%>selected<%}%> >
01</option>
<option <%if(number==2){%>selected<%}%> >
02</option>
<option <%if(number==3){%>selected<%}%> >
03</option>
<option <%if(number==4){%>selected<%}%> >
04</option>
</select>
关于java - 如何在JSP中动态选择一个值,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/51072088/