jsp如何获取下拉框的值
首先由两个页面 list.jsp 和getList.jsp
在list.jsp中有一个下拉框,他的值是从数据库中取得的,如何在getList.jsp中取得选中的值,(下面是list.jsp的source)
<%@ page language="java" contentType="text/html; charset=utf-8"
pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<%@ page import="net.taobaoge.dao.*"%>
<%@ page import="net.taobaoge.dao.impl.*"%>
<%@ page import="java.util.*"%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8">
<title>下拉框设置</title>
<%
InformationDAO dao = new InformationDAOImpl();
List<String> list = dao.getRegister();
for (int i = 0; i < list.size(); i++) {
System.out.println(list.get(i));
}
%>
</head>
<body>
<form action ="getList.jsp" method="post">
<select>
<option value=0>--请选择--</option>
<%
InformationDAO dao1 = new InformationDAOImpl();
List<String> list1 = dao.getRegister();
for (int i = 0; i < list1.size(); i++) {
%>
<option value=<%=i+1%>><%=list.get(i)%></option>
<%}%>
</select>
<input type="submit">
</form>
</body>
</html>
------解决方案--------------------<select name="sel">
<option value=<%=list.get(i)%>><%=list.get(i)%></option>
这就是你需要的值了
然后在getList.jsp中写
<%= request.getParameter("sel") %>