简体   繁体   English

Web服务矢量Java Glassfish的帮助

[英]Help with web service vector Java Glassfish

I currently have a web service which has a class to connect to a MySQL database to get customer information that is stored. 我目前有一个Web服务,该服务具有一个类以连接到MySQL数据库以获取存储的客户信息。

What I would like to do is get all the customer information as in username and add them into a new item in a combobox in the client side. 我想做的是获取用户名中的所有客户信息,并将它们添加到客户端组合框中的新项目中。 I know to use a Vector but I can't get my head around how I can get the web service to go through each entry, send it back and then update the combo box without a bunch of messy cod. 我知道会使用Vector,但是我无法理解如何使Web服务遍历每个条目,将其发送回去,然后更新组合框,而不会产生一堆乱七八糟的鳕鱼。

Can anyone help me out here? 有人可以帮我从这里出去吗?

Thanks. 谢谢。

If you want to use a web service properly, you should use a List not a Vector. 如果要正确使用Web服务,则应使用列表而不是向量。 This will translate to multiple XML elements in your WSDL. 这将转换为WSDL中的多个XML元素。

So for example if you have your web method named getCustomerInfo() and you are expecting it to return a list of strings, it would be like this: 因此,例如,如果您有一个名为getCustomerInfo()的Web方法,并且希望它返回一个字符串列表,则将是这样的:

@WebMethod
List<String> getCustomerInfo()
{
 //your normal Java code
}

Since you're mentioning JDBC its unlikely that you actually need to return a String, but you'll probably need a simple class which has 2 strings, the key and the value. 由于您提到的是JDBC,因此不太可能实际需要返回String,但是您可能需要一个包含2个字符串(键和值)的简单类。 For example 'Username' and 'sandeep'. 例如“用户名”和“ sandeep”。

Alternatively (the right way), use JPA and create a proper entity which reflects the proper table structure, and return that to the client. 或者(使用正确的方法),使用JPA并创建一个反映适当表结构的适当实体,然后将其返回给客户端。 Thats why JPA was designed for EJB3, and giving you're using Glassfish you've already got everything out of the box. 这就是为什么JPA是为EJB3设计的,并且为您提供了使用Glassfish的便利,因此您已经拥有了所有可用的功能。

UPDATE (following comments discussion): 更新(以下评论讨论):

So essentially what you need to have is your webservice do something like this: 所以从本质上讲,您需要的是Web服务执行以下操作:

@WebMethod
List<String> getCustomerUsernames()
{
  List<String> usernames = new ArrayList<String>();

  //your query here to get the usernames from the DB and for each username:
  usernames.add(username);

  return usernames;
}

From the client side you will first need to generate the web service stubs, which will then give you the identical method getCustomerUsernames() to use. 从客户端,您首先需要生成Web服务存根,然后将为您提供相同的方法getCustomerUsernames()来使用。

For more info about web services and JAX-WS refer to the tutorial here 有关Web服务和JAX-WS的更多信息,请参考此处教程。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM