jsp 获得checkbox值并写入数据库

73 篇文章 0 订阅

jsp 获得checkbox值并写入数据库,可通过以下方法:

    1.获得checkbox的值,并传入数组中

    2.将数组值转化为字符串

    3.写入数据库

例子:

        Checkbox.htm

<!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>test</title>
    </head>

    <body>
<form name="myform" id="myform" method="post" action="CorAdd.jsp">  
        <label>
            <input type="checkbox" name="CorpMode" value="1" />物品
        </label>
        <label>
            <input type="checkbox" name="CorpMode2" value="2" />人头
        </label>
        <label>
            <input type="checkbox" name="CorpMode2" value="3" />其他
        </label>      
        <input name="" type="button"οnclick="document.myform.action='Submit.jsp?menu=add'" />
</form>
    </body>
</html>

 

   提交页面 : Submit.jsp

 

<%@ page contentType="text/html; charset=utf-8" language="java" import = "java.util.*, java.text.*,java.sql.*"%>

<%
    if(menu.equals("add"))
{

    String tmp="";
    String SCorpMode="";
    String[] CorpMode = request.getParameterValues("CorpMode");
    if(CorpMode.length>0)
        {
            for(int i=0;i<CorpMode.length;i++)
            { 
                SCorpMode=SCorpMode+CorpMode[i]+","; 
            }
            SCorpMode=SCorpMode.substring(0,SCorpMode.length()-1);//去掉SID中的最后一个逗号 
        }

tmp ="insert into Corporation (CorpMode) values('+SCorpMode+');

    if(dbc.executeUpdate(tmp)>=0)
       out.println("<script>alert('信息添加成功!');location.href='CorpAdd.jsp'</script>");
    else
        
        //out.println("<script>alert('添加失败!');location.href='CorpAdd.jsp'</script>");
        out.print(tmp);
}
}
%>

 

本文来自CSDN博客,转载请标明出处:http://blog.csdn.net/zzlnet/archive/2008/08/25/2825516.aspx

  • 0
    点赞
  • 2
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值