开发者

Best way to pass values of multiple checkboxes to server

What is the best solution to this scenario: I have a SOAP based webservice implemented in Netbeans where the client is supposed to click on a number of checkboxes which are then sent to server and stored. Suppose my webservice has these checkboxes where all or some can be selected:

Ethnicity: 1.Caucasian 2.South-Est Asian 3.South Asian 4.African 5.Other

in another part of the same webservice i have implemented the checkboxes related to

Sex: 1.Maschio 2.Femmina

As following where either one or both can be selected but the solution looks very complicated to me for the Ethnicity part and i have other parts with even more checkboxes!

Client side code:

     private void salvaActionPerformed(java.awt.event.ActionEvent evt) {                                      
        // TODO add your handling code here:
           disease=malattia.getText();
           etastr=eta.getText();
           age=java.lang.Integer.parseInt(etastr);
           description=descrizione.getText();

         //Here i'm initiating the array using sexint as the dimension
         sexarra=new String[sexint];
        if(sexint==1)
        sexarra[0]=sexone;
        else if(sexint==0)
            JOptionPane.showMessageDialog(null, "Bisogna specificare     almeno un valore del campo sesso", "Errore", JOptionPane.ERROR_MESSAGE);
        else{
            sexarra[0]=sexone;
            sexarra[1]=sextwo;}


         // I define the parameters and afterwards send them to server
          Vector parametri = new Vector();
                  parametri.addElement(new Parameter("malattia", String.class, disease, null));
                 parametri.addElement(new Parameter("age", int.class, age, null));
                 parametri.addElement(new Parameter("descrizione", String.class, description, null));
                    parametri.addElement(new Parameter("sexarra",String[].class, sexarra, null));



       //Code related to calculating sexint which is used above as the dimension to array


     private void femminaActionPerformed(java.awt.event.ActionEvent evt) {                       开发者_StackOverflow                 
        // TODO add your handling code here:

        if(femmina.isSelected()){
            if(sexint==0){
              sexint++;
              sexone=femmina.getText();

            }

            else if(sexint==1){
            sexint++;

            sextwo=femmina.getText();
            }
            else
            sexint--;
        }
        }                                       

        private void maschioActionPerformed(java.awt.event.ActionEvent evt) {                                        
        // TODO add your handling code here:
              if(maschio.isSelected()){
            if(sexint==0){
              sexint++;
              sexone=maschio.getText();

            }

            else if(sexint==1){
            sexint++;

            sextwo=maschio.getText();
            }
            else
            sexint--;
        }
        }                

Code related to the server side:

       public String aggiungi_malattia(String malattia, int eta, String descrizione, String[] sexarra) {
                String ris = "no";
                String q = null, w = null;
                String errore = connetti();

               if(sexarra.length == 2){
         q = "INSERT INTO malattia (nome, eta, descrizione, sesso) "
                    + "VALUES ('" + malattia + "','" + eta + "','" + descrizione + "','" + sexarra[0] + "')";
         w="INSERT INTO malattia (nome, eta, descrizione, sesso) "
                    + "VALUES ('" + malattia + "','" + eta + "','" + descrizione + "','" + sexarra[1] + "')";
               }
         {
          q = "INSERT INTO malattia (nome, eta, descrizione, sesso) "
                    + "VALUES ('" + malattia + "','" + eta + "','" + descrizione + "','" + sexarra[0] + "')";

Thank you all for your time and effort!

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜