jspはcheckboxの値を得て、そしてデータベースに書きます。


jspはcheckboxの値を得てデータベースに書き込むことができます。 
    1.checkboxの値を取得し、配列に入る    2.配列値を文字列に変換する    3.データベースに書き込む
例:        Checkbox.httm
<!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"onclick="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+",";   
            } 
            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); 
} 
} 
%>