2011-02-24 15 views
0

我正在將6年前的應用程序轉換爲Seam 2.2。 該應用程序用於運行在java 1.4和weblogic 8中。 它只使用jsp和servlet。 在一個servlet的我用:Seam和ServletOutputStream - 刷新不會立即可見

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通過縫過濾雲:

<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> 
+0

還有另一種解決方案,我在幾個論壇上都看到迄今工作,無任何副作用:'<網址:Ajax4jsf的過濾力解析器=「假」 啓用緩存=「真「 regex-url-pattern =」。* \。seam |。* \。css |/a4j。*「/>'我在'components.xml'中加入了我的'old'servlet,立即刷新輸出。 – Guus 2011-03-04 11:50:33

回答

2

原因可能是請求通過SeamFilter,正如你所想的那樣。 我認爲SeamFilter本身不是緩衝來自servlet的數據流,而是緩衝過濾器鏈中調用的Ajax4Jsf過濾器。

如果在類路徑中有RichFaces,則會有一個seam組件在鏈中註冊Ajax4jsf過濾器。即,Seam組件是org.jboss.seam.web.ajax4jsfFilter

如果您不需要RichFaces,請嘗試從類路徑中刪除它。如果您需要它,我建議您覆蓋org.jboss.seam.web.ajax4jsfFilter以跳過針對您的servlet的請求的Ajax4Jsf過濾器。

另一種可能的解決方案是將您的servlet作爲Seam組件轉換爲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); 
     } 
    } 
+0

它的工作原理!非常感謝! – Guus 2011-03-01 07:19:34

2

你正在運行一個servlet - 沒有什麼做與Seam這裏。我懷疑你需要重新評估你的設計,因爲從servlet到Seam結構並沒有真正的翻譯。

+0

我不想將Servlet更改爲Seam結構。它運行良好,沒有時間去改變它。唯一的問題是刷新消息到瀏覽器窗口,現在只發生在servlet停止運行之後。之前,它立即將數據刷新到瀏覽器。 – Guus 2011-02-25 13:26:57

+1

那麼爲什麼要使用Seam呢?你沒有從中受益,這可能使你的應用程序變得複雜。將它構建並部署爲適當的J2EE WAR或EAR並以此方式使用它。 – TrueDub 2011-02-25 16:14:14

+0

因爲其餘部分正在轉換爲Seam。這是我們目前唯一的問題。其餘的運行良好。 – Guus 2011-02-26 07:02:51