是否可以将Swicthcase放入While循环中?我正在尝试,但我不能将值传递给另一个页面,它只显示null
<form action="NewFile1.jsp" method="get">
Birthday: <br>
<%! int i = 1, j;
String mon = "";%>
<%
out.println("<select name='month'>");
while(i <= 12) {
out.print("<option>" + i + "</option>");
i++;
}
out.print("</select>");
%>
<input type="submit" value="submit">
</form>
</body>
页面在组合框中输出所选值
<body>
<%
//String mo = request.getParameter("month");
String mo = "";
switch(request.getParameter("month")) {
case "1": mo = "January"; break;
}
%>
<%=out.print("Birthday: " + mo)%>
例如,在组合框中是分别代表月份的数字。如果用户选择2,则应在下一页上删除“二月”。
答案 0 :(得分:1)
尝试使用int而不是String:
<%
String mo = "";
int month = Integer.parseInt("0"+request.getParameter("month"));
switch(month) {
case 1: mo = "January"; break;
...
}
%>
<%=mo%>