当webservice中操作的返回类型为STRING []时,从webservice获取属性到servlet时出现问题

发布于 2024-08-14 05:08:35 字数 958 浏览 3 评论 0原文

我做了一个Webservice操作,其返回类型是STRING [] 以下是代码

@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 代码中的返回语句中,我有任何表的属性 我想将这些属性传递给 servlet,以便我可以在前端看到它们 但我在这里得到的是唯一的最后一个属性

谢谢!

I made a Webservice Operation whose return type is STRING []
Following is the code

@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;**

}

And then i made a Servlet
The code of the servlet thing is :

      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
             }

Problem is in my WEbservice Code in RETURN STATEMENT i have attributes of any table
and i want to take these attributes to servlet so that i can see them on my front end
but what im getting here is the only the LAST ATTRIBUTE

Thanks!

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

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

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

拥醉 2024-08-21 05:08:35

这是你处理 String 返回类型的 Webservice 操作的方式

 @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();
}

}

This is the way u can handle Webservice Operation of String Return type

 @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();
}

}

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文