Seam 和 ServletOutputStream - 刷新不会立即可见
我正在将一个已有 6 年历史的应用程序转换为 Seam 2.2。 该应用程序用于在java 1.4和weblogic 8中运行。 它只使用jsp和servlet。 在我使用的一个 servlet 中:
public void doGet (HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
//...
ServletOutputStream out = = res.getOutputStream();
// displaying a lot of messages
// after each println() I do a flush()
out.println("lots of messages.....");
out.flush();
out.close();
//...
}
运行应用程序时,消息会立即在浏览器中看到。
当我在 Weblogic 10 和 Java 1.6 中使用 Seam 2.2 运行此命令时,浏览器中不会立即看到消息。 仅当 servlet 运行完毕时。
我可以改变一些东西来解决这个问题吗?
我不想将 servlet 更改/转换为 Seam 组件。 servlet 运行良好。唯一的事情是将消息刷新到浏览器窗口,这仅在 servlet 停止运行后发生。
难道是因为servlet现在要经过Seam过滤器:
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
I am converting a 6 year old application to Seam 2.2.
The application is used to run in java 1.4 and weblogic 8.
It only uses jsp and servlet.
In one servlet I use:
public void doGet (HttpServletRequest req,HttpServletResponse res) throws ServletException,IOException
{
//...
ServletOutputStream out = = res.getOutputStream();
// displaying a lot of messages
// after each println() I do a flush()
out.println("lots of messages.....");
out.flush();
out.close();
//...
}
When running the application the messages were immediately seen in the browser.
When I run this using Seam 2.2 in Weblogic 10 and Java 1.6 the messages are not immediately seen in the browser.
Only when the servlet is finished running.
Can I change something to fix this?
I do not want to change/convert the servlet into a Seam component. The servlet is running fine. The only thing is the flushing of messages to the browser window which only happens after the servlet has stopped running.
Could it be that the reason is that the servlet now goes through the Seam filter:
<filter>
<filter-name>Seam Filter</filter-name>
<filter-class>org.jboss.seam.servlet.SeamFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Seam Filter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
原因可能是请求通过了 SeamFilter,如您所料。
我认为缓冲来自 servlet 的数据流的不是 SeamFilter 本身,而是过滤器链中调用的 Ajax4Jsf 过滤器。
如果类路径中有 RichFaces,则有一个接缝组件会在链中注册 Ajax4jsf 过滤器。也就是说,Seam 组件是
org.jboss.seam.web.ajax4jsfFilter
。如果您不需要 RichFaces,请尝试将其从类路径中删除。如果您需要它,我建议您重写
org.jboss.seam.web.ajax4jsfFilter
,以便针对定向到您的servlet 的请求跳过Ajax4Jsf 过滤器。另一种可能的解决方案是将过滤器中的 servlet 转换为 Seam 组件(请参阅 @Filter 注释),并使用 around 属性将其定位在链的开头。像这样的东西:
The reason is probably that the request goes through the SeamFilter, as you supposed.
I think it's not the SeamFilter itself that buffer the data stream from your servlet but the Ajax4Jsf filter that is invoked in the filter chain.
If you have RichFaces in the classpath there is a seam component that registers the Ajax4jsf filter in the chain. Namely, the Seam component is
org.jboss.seam.web.ajax4jsfFilter
.If you don't need RichFaces try removing it from the classpath. If you need it, I suggest that you override
org.jboss.seam.web.ajax4jsfFilter
in order to skip the Ajax4Jsf filter for requests directed to your servlet.Another possible solution is converting your servlet in a filter as a Seam component (see @Filter annotation) and positioning it at the beginning of the chain with the around attribute. Something like:
您正在运行一个 servlet - 这里与 Seam 无关。我怀疑您需要重新评估您的设计,因为实际上并没有从 servlet 到 Seam 结构的精确转换。
You're running a servlet - there's nothing to do with Seam here. I suspect you need to re-evaluate your design, as there's not really an exact translation from servlet to Seam structure.