如何将信息放入 Tapestry5 的输出流中?
如何将信息放入 Tapestry5 的输出流中?
当用户输入它时,我需要一个页面,打开一个对话框以保存或打开带有输出流信息的文件。
我编写下一个代码:
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);
}
}
}
我希望结果只是“hellooooooooo”,但是是(“hellooooooooo”+我的html原始页面)
How Can I put information in a outputstream from 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)
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
您的方法应该具有 StreamResponse 的返回类型。 您返回 StreamResponse 接口的实现,它只是返回您想要的数据以及您想要的内容类型。
在这里查找:
http://tapestry.apache.org/tapestry5/apidocs/
更多信息在这里:
http://tapestry.formos.com/ nightly/tapestry5/tapestry-core/guide/pagenav.html
Your method should have a return type of StreamResponse. You return an implementation of the interface StreamResponse, which simply returns the data you want with the content type you want.
Look it up here:
http://tapestry.apache.org/tapestry5/apidocs/
more info here:
http://tapestry.formos.com/nightly/tapestry5/tapestry-core/guide/pagenav.html
如果您正在处理大型响应流,请使用 StreamResponse可能有点不方便且效率低下(因为您必须返回 输入流)。 更好的方法是直接将响应写入 OutputStream 。
幸运的是,在 Tapestry Wiki 中,有一个页面可以准确解决此问题:Tapestry5:如何创建组件事件结果处理器。
If you are dealing with large response streams, using StreamResponse can be somewhat inconvenient and inefficient (because you have to return an InputStream). Better would be to write response directly to OutputStream.
Fortunately, in Tapestry Wiki, there is a page for solving exactly this: Tapestry5: How To Create A Component Event Result Processor.