㈠ 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>
運行界面: