日期:2014-05-18  浏览次数:20573 次

用Servlet做表单提交连接数据库等综合问题
我要给一个web页面上的内容作数据库连接   这是一个要提交的表单   里面有很多复选框   我用html做的   然后我要另外写一个Java类用于收集这些数据   request.getparameter( "复选框名字 ")   这是一个什么类型的数据   我怎样判断它是否选中   isselected()点不出来的   具体怎么做   还有进入数据库我想把boolean值转换成bit类型的   请高手赐教!!!   有没有这方面的例子?

------解决方案--------------------
request.getParameter就行了啊。要是你的复选框有被选中的话,就会得到值。
多个被选中的话得到的就是个数组。

test.jsp

<html>
<head> <title> lskj </title> </head>
<body>
<form method=post action= "test1.jsp " >
<input type= "checkbox " name= "aa " value= "bb ">
<input type= "checkbox " name= "aa " value= "aa ">
<input type= "checkbox " name= "aa " value= "cc ">
<input type= "checkbox " name= "aa " value= "dd ">
<input type= "checkbox " name= "aa " value= "ee ">
<input type= "checkbox " name= "aa " value= "ff ">
<input type= "checkbox " name= "aa " value= "gg ">
<input type=submit value= "submit ">
</form>
</html>

test1.jsp

<html>
<head> <title> sflj </title> </head>
<body>
<%
String []results = request.getParameterValues( "aa ");
if(results != null){
for(int i = 0 ; i < results.length; i ++)
out.print(results[i]);
}

%>

</body>
</html>