首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > Java Web开发 >

写入数据库控制不了,无论条件满不满足,一点出提交就将数据写入数据库解决思路

2012-03-06 
写入数据库控制不了,无论条件满不满足,一点出提交就将数据写入数据库%@pagelanguage java import ja

写入数据库控制不了,无论条件满不满足,一点出提交就将数据写入数据库
<%@   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   =   address.indexOf( "http:// ",0);
  //if(id   ==   0)


  //address   =   address.substring(7);
  if(Value==null   ||   Value.equals( "1 "))
  Value= "13 ";
  if(Value   !=   null&&   address   !=   null   &&   name   !=   null   ){
  try{
  resource.executeUpdate( "insert   into   collectioncontent   values( ' "+   benwei   + " ', ' "+   Value   + " ', ' "+   address   + " ', ' "+   name   + " ') ");
  out.print( " <script> alert( '收藏网址成功,关闭请退出... '); </script> ");
  }
  catch(Exception   e){
  out.print( " <script> alert( '收藏网址失败,请正确输入网址信息... '); </script> ");
  }
  }
  else
  out.print( " <script> alert( '收藏网址失败,请正确输入网址信息... '); </script> ");
%>
</form>
</body>
</html>

[解决办法]
试试
onsubmit= "return checkdata(this) ">
[解决办法]
1在所用到的方法中写一alert,如果按钮触发了这个方法,那将会有alert弹

<input name= " " type= "submit " value= "提交 "onclick="return checkdata(this)" />

[解决办法]
把最后一个 return true; 去掉不知可不可以。

<input name= " " type= "submit " value= "提交 " /> 这句我的习惯用法是

<form name= "form1 " action= "add.jsp " method= "post ">
。。。。。。
<input name= " " type= "submit " value= "提交 " onclick= "checkdata(this) "/>

[解决办法]
shuai45(付出总有回报,要做就做最好.)
同意,

热点排行