Is there a way to get struts 2 (using tiles) to build the whole page before sending it to the browser? I don't want the page to be build "progressively" in the browser one part at a time.
有没有办法让struts 2(使用tile)在将整个页面发送到浏览器之前构建整个页面?我不希望页面一次一个地在浏览器中“逐步”构建。
The main problem I'm trying to solve is that internet explorer 7 flashes/blinks the page even if only some of the content changes (firefox does this much more smoothly).
我试图解决的主要问题是Internet Explorer 7闪烁/闪烁页面即使只有一些内容发生了变化(firefox做得更顺利)。
So that if I have a page with:
所以,如果我有一个页面:
HEADER
some content
FOOTER
And the "some content" area only changes between page loads, the FOOTER part still flashes the white background before filling it with the background color of the footer. I tought that maybe by getting struts to send the complete page it would load fast enough to eliminate the "blinking". Now the FOOTER comes from the server a little bit later than the parts before it and so it flashes (in internet explorer, firefox displays the page smoothly).
并且“某些内容”区域仅在页面加载之间发生变化,FOOTER部分仍然会在填充页脚的背景颜色之前闪烁白色背景。我认为这可能是通过让struts发送整个页面来加载足够快以消除“闪烁”。现在FOOTER来自服务器比它之前的部件晚一点,所以它闪烁(在Internet Explorer中,firefox顺利显示页面)。
NB: this is an important requirement for the site, and using ajax to load the middle content is out (as are frames or other "hacks"). The site is built using CSS and not a table layout, maybe I will have to use a table layout to get it to work...
注意:这是网站的一个重要要求,并且使用ajax加载中间内容(框架或其他“黑客”)也是如此。该网站是使用CSS而不是表格布局构建的,也许我将不得不使用表格布局来使其工作......
About using tiles flush parameter: I tried that and it doesn't work as I need. I would need a flush-parameter for the whole page. I have tried the normal jsp page directive "autoFlush=false" but it didn't work. I set this directive on my main template page (and not in the tiles).
关于使用tile flush参数:我试过了,它不能正常工作。我需要整个页面的flush参数。我尝试过普通的jsp页面指令“autoFlush = false”,但它没有用。我在我的主模板页面上设置了这个指令(而不是在tile中)。
Here is an example from the main template, which uses header, body and footer templates. With the Thread.sleep() I added the problem is easy to spot. The footer renders 2 secs later than the rest of the page.
以下是主模板中的示例,该模板使用页眉,正文和页脚模板。使用Thread.sleep()我添加了问题很容易发现。页脚比页面的其余部分晚2秒。
<body>
<div id="container">
<t:insertAttribute name="header" flush="false" />
<div id="content"><t:insertAttribute name="body" flush="false"/></div>
<div class="clear"></div>
<% Thread.sleep(2000); %>
<t:insertAttribute name="footer" flush="false" />
</div>
</body>
UPDATE
Thanks for the comments. The requirement is actually almost reasonable as this isn't a normal web page, think embedded.
感谢您的评论。这个要求实际上几乎是合理的,因为这不是一个普通的网页,想想嵌入式。
But apparently there is no way of configuring IE to start rendering after some delay (like firefox has a configurable delay of some 100ms)?
但显然没有办法配置IE在一些延迟后开始渲染(比如firefox有可配置的延迟大约100ms)?
I tried to intercept the TilesResult but the method doExecute is run before the whole content is apparently evaluated, so the method has already exited before the jsp is evaluated (my Thread.sleep() test). I was wondering how I could render the whole response to a string and then output that all at once to the browser.
我试图拦截TilesResult但是方法doExecute在显然评估整个内容之前运行,因此该方法在评估jsp之前已经退出(我的Thread.sleep()测试)。我想知道如何将整个响应呈现给字符串,然后将所有响应一次性输出到浏览器。
I know that this isn't foolproof and network delays etc may factor in this, but if I could get the response to output all at once and maybe use a table based layout (IE possibly renders the table only after the table closes) this could work reasonably.
我知道这不是万无一失的,网络延迟等可能会影响到这一点,但是如果我可以立即得到所有输出的响应并且可能使用基于表的布局(IE可能只在表关闭后呈现表)这可能合理地工作。
Or then try to get this switched to firefox or maybe forget all about this little glitch...
或者然后尝试将此切换到Firefox或者可能忘记所有关于这个小故障......
UPDATE 2
This started to bother me so I did some investigation. If I had a plain jsp page (no tiles) the buffering works (with the buffer attribute), so that if I had my Thread.sleep() there the whole page rendered after two seconds if the page size was below the buffer size. But if I used tiles in the page (as in the example above) I couldn't get the page to render at the same time (I even included the page directive in all my tiles-templates/"components", no help). So tiles probably flushes the response somewhere?
这开始打扰我,所以我做了一些调查。如果我有一个普通的jsp页面(没有tile)缓冲工作(使用buffer属性),那么如果我有Thread.sleep(),那么如果页面大小低于缓冲区大小,那么整个页面会在两秒后呈现。但是,如果我在页面中使用了tile(如上例所示),我无法同时呈现页面(我甚至在所有tile-templates /“components”中都包含了page指令,没有帮助)。那么瓷砖可能会在某处冲洗响应?
Furthermore, the "problematic tiles" was my body-part, which contained a struts:form tag. I replaced it with a normal form-tag and it worked as I wanted...
此外,“有问题的瓷砖”是我的身体部分,其中包含一个struts:form标签。我用普通的表格标签替换它,它按我想要的方式工作......
UPDATE 3
Ok, nobody seems to know the inner workings of tiles or struts tags... No big problem as this is a very specific case and requirement. I worked around it by using apache as a proxt in front of the application, and using apache's proxy configuration options to specify a large buffer. I'll mark this as answered.
好吧,似乎没有人知道瓷砖或支柱标签的内部工作原理......没有大问题,因为这是一个非常具体的案例和要求。我通过在应用程序前面使用apache作为proxt并使用apache的代理配置选项指定一个大缓冲区来解决它。我会将此标记为已回答。
2 个解决方案
#1
Can you use the "flush" attribute on the tiles components?
你可以在tiles组件上使用“flush”属性吗?
<tiles:insertAttribute name="body" flush="false"/>
In addition if the output buffer gets too big, it will flush anyway. Try increasing the buffer size?
此外,如果输出缓冲区太大,它仍然会刷新。尝试增加缓冲区大小?
<%@ page language="java" buffer="500kb" autoFlush="false" %>
#2
You can send page data all at once at the server end if you like (and many frameworks do that anyway for convenience) but the reality of networking is that it won't all arrive at once and the browser will render it as packets arrive. And this is a good thing for responsiveness, even if you* aesthetically would like the page to display all at once.
如果你愿意,你可以在服务器端一次性发送页面数据(为方便起见,许多框架都是这样做的)但网络的实际情况是它不会一次全部到达,浏览器会在数据包到达时呈现它。这对于响应性来说是一件好事,即使你在美学上希望页面能够同时显示。
You can reduce the lag as much as possible by simplifying markup and using deflate compression to keep the payload size down, and that's a worthwhile thing to do in general. Plus you can make sure you're not hitting a Flash Of Unstyled Content. But you can't control when the browser chooses to render, short of doing it all in JavaScript with all the downsides that entails (and even then, the browser might redraw slowly).
您可以通过简化标记和使用deflate压缩来减少滞后,以保持有效负载大小,这是一件值得做的事情。另外,你可以确保你没有点过Flash Unstyled Content。但是你无法控制浏览器何时选择渲染,而不是在JavaScript中完成所有需要的所有缺点(即便如此,浏览器可能会慢慢重绘)。
(* - or your client/boss, if that's who has come up with this "important requirement" that your site somehow work differently to every other page on the web.)
(* - 或者您的客户/老板,如果有人提出这个“重要要求”,那么您的网站在某种程度上与网络上的其他每个页面的工作方式不同。)
#1
Can you use the "flush" attribute on the tiles components?
你可以在tiles组件上使用“flush”属性吗?
<tiles:insertAttribute name="body" flush="false"/>
In addition if the output buffer gets too big, it will flush anyway. Try increasing the buffer size?
此外,如果输出缓冲区太大,它仍然会刷新。尝试增加缓冲区大小?
<%@ page language="java" buffer="500kb" autoFlush="false" %>
#2
You can send page data all at once at the server end if you like (and many frameworks do that anyway for convenience) but the reality of networking is that it won't all arrive at once and the browser will render it as packets arrive. And this is a good thing for responsiveness, even if you* aesthetically would like the page to display all at once.
如果你愿意,你可以在服务器端一次性发送页面数据(为方便起见,许多框架都是这样做的)但网络的实际情况是它不会一次全部到达,浏览器会在数据包到达时呈现它。这对于响应性来说是一件好事,即使你在美学上希望页面能够同时显示。
You can reduce the lag as much as possible by simplifying markup and using deflate compression to keep the payload size down, and that's a worthwhile thing to do in general. Plus you can make sure you're not hitting a Flash Of Unstyled Content. But you can't control when the browser chooses to render, short of doing it all in JavaScript with all the downsides that entails (and even then, the browser might redraw slowly).
您可以通过简化标记和使用deflate压缩来减少滞后,以保持有效负载大小,这是一件值得做的事情。另外,你可以确保你没有点过Flash Unstyled Content。但是你无法控制浏览器何时选择渲染,而不是在JavaScript中完成所有需要的所有缺点(即便如此,浏览器可能会慢慢重绘)。
(* - or your client/boss, if that's who has come up with this "important requirement" that your site somehow work differently to every other page on the web.)
(* - 或者您的客户/老板,如果有人提出这个“重要要求”,那么您的网站在某种程度上与网络上的其他每个页面的工作方式不同。)