1

我做了一个返回类型为 STRING [] 的 Webservice Operation 以下是代码

@WebMethod(operationName = "authorize")
public String [] authorize(@WebParam(name = "Username")
String Username) {
    CAuthorization CA = new CAuthorization();
    String [] Result= null;
       try {
        Result = CA.CheckAuthorization(Username);
    } catch (SQLException ex) {
        Logger.getLogger(WS_Authentication.class.getName()).log(Level.SEVERE, null, ex);
    }

    **return Result;**

}

然后我做了一个 Servlet servlet 的代码是:

      try { // Call Web Service Operation


                 java.lang.String result = null;
                     result =  port.authorize(Username);
                 out.println("Result = "+result);
             } catch (Exception ex) {
                 // TODO handle custom exceptions here
             }

问题出在我的 WEBservice 代码中的 RETURN STATEMENT 我有任何表的属性,我想将这些属性带到 servlet 以便我可以在前端看到它们,但我在这里得到的是唯一的 LAST ATTRIBUTE

谢谢!

4

1 回答 1

0

这是您可以处理字符串返回类型的Web服务操作的方式

 @WebMethod(operationName = "authorize")
    public String authorize(@WebParam(name = "Username")
   String Username) {

    CAuthorization CA = new CAuthorization();
    StringBuffer result = new StringBuffer();
    try {
        if (CA.CheckAuthorization(Username).length > 0) {
            result.append(CA.CheckAuthorization(Username)[0]);
            for (int i = 1; i < CA.CheckAuthorization(Username).length; i++) {
                result.append(",");
                result.append(CA.CheckAuthorization(Username)[i]);
            }
        }
    } catch (SQLException ex) {
        Logger.getLogger(WS_Authentication.class.getName()).log(Level.SEVERE, null, ex);
    }
    //TODO write your implementation code here:
    return result.toString();
}

}

于 2010-01-31T13:00:42.177 回答