我想在下拉列表中按/选择一些值时检查服务器端。我怎么能这样做?
我尝试如下:
code : for list
<select id="stream" name="current_session" >
<option value="Winter">Winter</option>
<option value="Monsoon">Monsoon</option>
</select>
code : for button
<form>
<input type="button " name="btn" value ="button">
code : for sriplet
if(request.getParameter("current_session")!=null)
{
system.out.println("helo ur list test is okey ");
}
if(request.getParameter("btn")!=null)
{
system.out.println("helo ur test for button is okey ");
}
注意:当我使用按钮时,按下按钮时工作正常,但是当我选择列表时它不起作用。
答案 0 :(得分:0)
将一个on-change侦听器附加到您的select标签,该标签可以触发ajax请求,然后您可以执行服务器端检查并返回可以在客户端处理的响应。
<select id="stream" name="current_session" >
<option value="Winter">Winter</option>
<option value="Monsoon">Monsoon</option>
</select>
<script>
$( "#stream" ).change(function() {
var selectedVal=$("#stream option:selected").val();
$.ajax({
url:"checkonserver.jsp?current_session="+selectedVal,
success:function(msg){
alert(msg);
}
});
});
</script>
<强> checkonserver.jsp 强>
<% if(request.getParameter("current_session").toString().equals("Winter")){%>
It's COLD
<%}else{%>
It's HOT
<%}%>