菜鸟问题 JSP
一个下拉框,里面有学生,老师,管理员三种身份
我怎么得到下拉列表所选的值,然后选择不同的SQL语句~~~
------解决方案--------------------request.getParameter( " ");
------解决方案--------------------document.getElementById( "sel ").options[document.getElementById( "sel ").selectedIndex].value
------解决方案--------------------给你一个实例:
1.html
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 传送页面 </title>
</head>
<body>
<form action= "1.jsp " method= "post " enctype= "application/x-www-form-urlencoded " name= "form1 " id= "form1 ">
<select name= "select ">
<option value= "老师 "> 老师 </option>
<option value= "学生 "> 学生 </option>
<option value= "管理员 "> 管理员 </option>
</select>
</form>
</body>
</html>
下面是一个接收页
1.jsp
<%@ page contentType= "text/html; charset=gb2312 " language= "java " import= "java.sql.* "
errorPage= " " %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN " "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
<html xmlns= "http://www.w3.org/1999/xhtml ">
<head>
<meta http-equiv= "Content-Type " content= "text/html; charset=gb2312 " />
<title> 接收显示页面 </title>
</head>
<body>
<% request.setCharacterEncoding( "gb2312 ");
String select=request.getParameter( "select ");
out.println(select);
%>
</body>
</html>
------解决方案--------------------如楼上
------解决方案--------------------只需要测试传递过来的值用if(){}else{}搞定了
------解决方案--------------------如上,根据页面传过来的值选择不同的赋值语句就行了。。。
if(i==a)
{
sql= "select * form ... ";
}else if(i==b){
sql= "..... "
}else{
.....
}
之类的吧。。。还是楼主有其它意思?
------解决方案--------------------request.getParameter( " ");
在作个判断~~~