1
這種情況最好的解決方案是什麼:我在Netbeans中實現了一個基於SOAP的web服務,客戶端應該點擊一些複選框,然後發送到服務器並存儲。假設我的web服務具有這些複選框的全部或部分可選用:應該如何將多個複選框的值傳遞給服務器
種族: 1.Caucasian 2.South-EST亞洲 3.South亞洲 4.African (五)其他
在另一相同的web服務的一部分我已經實現有關
性別的複選框: 1.Male 2.Female
正如以下其中之一或都可以選擇,但解決方案看起來非常複雜,我的種族部分,我有更多的複選框的其他部分!
客戶端代碼:
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 femaleActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(female.isSelected()){
if(sexint==0){
sexint++;
sexone=female.getText();
}
else if(sexint==1){
sexint++;
sextwo=female.getText();
}
else
sexint--;
}
}
private void maleActionPerformed(java.awt.event.ActionEvent evt) {
// TODO add your handling code here:
if(male.isSelected()){
if(sexint==0){
sexint++;
sexone=male.getText();
}
else if(sexint==1){
sexint++;
sextwo=male.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] + "')";
謝謝大家的時間和精力!
非常感謝您的詳細回覆,我仍然試圖完全整合您的解決方案。問題是我已經在Netbeans的設計模式中創建了接口,因此有很多機器生成的代碼...再次感謝! – rosa