简体   繁体   English

如何将信息放入Tapestry5的输出流中?

[英]How Can I put information in a outputstream from tapestry5?

How Can I put information in a outputstream from tapestry5 ? 如何将信息放入tapestry5的输出流中?

I need a page when a user enters it open a dialog for save or open the file with the outputstream information. 当用户输入页面时,我需要一个页面,以打开一个对话框来保存或打开包含输出流信息的文件。

I write the next code: 我写下一个代码:

public class Index { 公共课索引{

@Inject
private RequestGlobals requestGlobals;

@OnEvent("activate")
public void onActivate() {
    try {
        HttpServletResponse response = requestGlobals.getHTTPServletResponse();
        response.setContentType("text/txt");
        PrintWriter out = response.getWriter();
        out.println("hellooooooo");
        out.flush();
    } catch (IOException ex) {
        Logger.getLogger(Index.class.getName()).log(Level.SEVERE, null, ex);
    }
}

} }

I hope that the result is only "helloooooooo" but is ("helloooooooo" + my html raw page) 我希望结果只是“ helloooooooo”而已(“ helloooooooo” +我的html原始页面)

Your method should have a return type of StreamResponse. 您的方法应具有StreamResponse的返回类型。 You return an implementation of the interface StreamResponse, which simply returns the data you want with the content type you want. 您返回接口StreamResponse的实现,该实现只是返回所需数据和所需内容类型的数据。

Look it up here: 在这里查找:

http://tapestry.apache.org/tapestry5/apidocs/ http://tapestry.apache.org/tapestry5/apidocs/

more info here: 更多信息在这里:

http://tapestry.formos.com/nightly/tapestry5/tapestry-core/guide/pagenav.html http://tapestry.formos.com/nightly/tapestry5/tapestry-core/guide/pagenav.html

If you are dealing with large response streams, using StreamResponse can be somewhat inconvenient and inefficient (because you have to return an InputStream ). 如果要处理大型响应流,则使用StreamResponse可能会带来一些不便和效率低下(因为必须返回InputStream )。 Better would be to write response directly to OutputStream . 最好将响应直接写到OutputStream

Fortunately, in Tapestry Wiki, there is a page for solving exactly this: Tapestry5: How To Create A Component Event Result Processor . 幸运的是,在Tapestry Wiki中,有一个页面可以完全解决此问题: Tapestry5:如何创建组件事件结果处理器

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

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