㈠ jsP页面获取Select值的问题
jsp页面获取select的值:
测试页面代码如下:
<%@ page language="java" import="java.util.*" pageEncoding="GB18030"%>
<%
request.setCharacterEncoding("GB18030");//加上这一句解决的
String path = request.getContextPath();
String basePath = request.getScheme() + "://"
+ request.getServerName() + ":" + request.getServerPort()
+ path + "/";
//存放下来菜单对应值的数组
ArrayList nu = new ArrayList();
nu.add("一");
nu.add("二");
nu.add("三");
%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<base href="<%=basePath%>">
<title>My JSP 'testselect.jsp' starting page</title>
</head>
<body>
通过request.getParameter("number")方法取得下拉框选取的值
<form method=post action="testselect.jsp"> <!-- 提交给自身 -->
<select name=number>
<%
for (int i = 0; i < nu.size(); i++) {
out.print("<option>" + nu.get(i) + "</option>");
}
%>
</select>
<input type="submit" value="提交" name="submit">
</form>
</body>
<%
//取得提交的数字,并显示
String n = (String) request.getParameter("number");
out.print("选的值是:" + n);
%>
</html>
运行界面: