简体   繁体   中英

Java Servlet return only a value

I have create a Java Servlet which calls method from my Web Service. The method works fine and I've tested it. But my problem is on the Servlet side.

I dragged and drop the method from the Server Client and modified abit. Below is my code as for now.

private ArrayList<String> search(java.lang.String shopName) throws ClassNotFoundException_Exception {
    // Note that the injected javax.xml.ws.Service reference as well as port objects are not thread safe.
    // If the calling of port operations may lead to race condition some synchronization is required.
    webservices.WebServices port = service.getWebServicesPort();

    ArrayList<String> shops = new ArrayList<String>();

    shops.add(port.search(shopName));

    System.out.println(port.search(shopName));

    return shops;
}

The problem I encounter right now is that it returns only a value and it is the last value but the actual output has more than one. I've tested my Web Service method and it returns all the result from the execution of the query but in this Servlet it returns the last. How do I make it count from the beginning till the end?

我认为您需要ArrayList.addAll()

shops.addAll(port.search(shopName));

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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