Seam 和 ServletOutputStream - 刷新不会立即可见

发布于 2024-10-18 17:20:06 字数 1159 浏览 1 评论 0原文

我正在将一个已有 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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你与清晨阳光 2024-10-25 17:20:06

原因可能是请求通过了 SeamFilter,如您所料。
我认为缓冲来自 servlet 的数据流的不是 SeamFilter 本身,而是过滤器链中调用的 Ajax4Jsf 过滤器。

如果类路径中有 RichFaces,则有一个接缝组件会在链中注册 Ajax4jsf 过滤器。也就是说,Seam 组件是org.jboss.seam.web.ajax4jsfFilter

如果您不需要 RichFaces,请尝试将其从类路径中删除。如果您需要它,我建议您重写org.jboss.seam.web.ajax4jsfFilter,以便针对定向到您的servlet 的请求跳过Ajax4Jsf 过滤器。

另一种可能的解决方案是将过滤器中的 servlet 转换为 Seam 组件(请参阅 @Filter 注释),并使用 around 属性将其定位在链的开头。像这样的东西:

@Name("FormerServlet")
@Scope(STATELESS)
@BypassInterceptors
@Filter(around = "org.jboss.seam.web.ajax4jsfFilterInstantiator")
public class FormerServletFilter implements Filter
{

    protected void init(FilterConfig filterConfig) throws Exception
    {
    }


    protected void doDestroy()
    {
    }

    /**
     * Performs the filtering for a request.
     */
    protected void doFilter(final HttpServletRequest request, final HttpServletResponse response,
                            final FilterChain chain) throws Exception
    {
        if (thisRequestShoudBeManagedByMyServlet(request) )
        {
           // do here what you previously did in the servlet

        } else
        {
            // go ahead with the Seam lifecycle
            chain.doFilter(request, response);
        }
    }

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:

@Name("FormerServlet")
@Scope(STATELESS)
@BypassInterceptors
@Filter(around = "org.jboss.seam.web.ajax4jsfFilterInstantiator")
public class FormerServletFilter implements Filter
{

    protected void init(FilterConfig filterConfig) throws Exception
    {
    }


    protected void doDestroy()
    {
    }

    /**
     * Performs the filtering for a request.
     */
    protected void doFilter(final HttpServletRequest request, final HttpServletResponse response,
                            final FilterChain chain) throws Exception
    {
        if (thisRequestShoudBeManagedByMyServlet(request) )
        {
           // do here what you previously did in the servlet

        } else
        {
            // go ahead with the Seam lifecycle
            chain.doFilter(request, response);
        }
    }
﹎☆浅夏丿初晴 2024-10-25 17:20:06

您正在运行一个 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.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文