简体   繁体   English

从Servlet向客户端发送数据的最佳方式?

[英]Bestway to send data from servlet to client?

Guyz, 盖茨

I have a servlet where i query data from mysql using jdbc. 我有一个servlet,我在其中使用jdbc从mysql查询数据。

I have a huge result set to send to client (atleast 3 column and 10 rows ) 我有一个巨大的结果集要发送给客户端(至少3列和10行)

What would be the the best way to send instead simply writing to the response stream like below? 发送而不是简单地写入如下所示的响应流的最佳方法是什么?

ResultSet toResults = toStatement.getResultSet();

        if (toResults.next()) {
            out.println(toResults.getString(1));
                    out.println(toResults.getString(2));
                    ....
                    ....

        }

First this does not sound the huge data. 首先,这听起来并不庞大。 Second what you mean by client? 第二,客户的意思是什么? If you have to display the data in Browser than you can create the List of VO's or List of string array. 如果必须在浏览器中显示数据,则可以创建VO列表或字符串数​​组列表。

If you are working on Ajax or your client is application, you can send data using XML or JSON. 如果您正在使用Ajax或客户端是应用程序,则可以使用XML或JSON发送数据。

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

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