将多个复选框的值传递到服务器的最佳方法

发布于 2024-11-29 23:42:18 字数 3566 浏览 1 评论 0原文

这种情况的最佳解决方案是什么:我在 Netbeans 中实现了一个基于 SOAP 的 Web 服务,其中客户端应该单击多个复选框,然后将这些复选框发送到服务器并存储。假设我的网络服务有这些复选框,可以选择全部或部分:

种族: 1.白种人 2.东南亚 3.南亚风味 4.非洲人 5.

在同一网络服务的另一部分中,我已经实现了与性别相关的复选框

: 1.马斯奇奥 2.Femmina

如下所示,可以选择其中之一或两者,但对于我来说,种族部分的解决方案看起来非常复杂,而且我还有其他部分有更多的复选框!

客户端代码:

     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) {                                        
        // 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--;
        }
        }                

与服务器端相关的代码:

       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] + "')";

谢谢大家的时间和精力!

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) {                                        
        // 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!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。
列表为空,暂无数据
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文