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

写入数据库控制不了,无论条件满不满足,一点出提交就将数据写入数据库
<%@   page   language= "java "   import= "java.sql.* "   pageEncoding= "GB2312 "%>
<%@   page   import= "java.lang.String "   %>
<html>
<head>
<meta   http-equiv= "Content-Type "   content= "text/html;   charset=GB2312 ">
<SCRIPT   language=JavaScript   type= " ">
function   checkdata(thisform)   {

if   (thisform.type.value== " ")   {
alert( "请选择网站类型! ");
thisform.type.focus();
return   false;
}

if   (thisform.webaddress.value== " ")   {
alert( "请输入网站地址! ");
thisform.webaddress.focus();
return   false;
}
if   (thisform.webname.value== " ")   {
alert( "请输入网站名称! ");
thisform.webname.focus();
return   false;
}
return   true;
}
</SCRIPT>
</head>
<body   bgColor=#ffcc00>
<form   action= "add.jsp "   method= "post "   onsubmit= "checkdata(this) ">
<table   width= "300 "   border= "0 "   align= "center ">
    <tr>
        <td> 请选择网站类型: </td>
        <td> <select   name= "type ">
<jsp:useBean   id= "resource "   scope= "page "   class= "sju.sjumis.yuanding.util.TeacherDBBean "> </jsp:useBean>
  <%ResultSet   rs   =   resource.executeQuery( "select   *   from   collectionclass ");
while(rs.next()){%>
<option   value= " <%=rs.getString(1)%> "> <%=rs.getString(2)%> </option>
<%}  
resource.closeStmt();%>
  </select> </td>
    </tr>
    <tr>
        <td> 请输入网站地址: </td>
        <td> <input   type= "text "   name= "webaddress "   maxlength= "50 "/> </td>
    </tr>
    <tr>
        <td> 请输入网站名称: </td>
        <td> <input   name= "webname "   type= "text "   maxlength= "20 "   /> </td>
    </tr>
    <tr>
        <td   align= "center "> <input   name= " "   type= "submit "   value= "提交 "   /> </td>
        <td   align= "center "> <input   name= " "   type= "reset "   value= "重置 "   /> </td>
    </tr>
</table>

<%
//int   id   =-1;
String   benwei   =   "benwei ";
  String   Value   =   request.getParameter( "type ");
  String   address   =   request.getParameter( "webaddress ");  
  String   name   =   request.getParameter( "webname ");
  //id &nb