JSP out.flush() 问题

发布于 2024-12-24 04:03:47 字数 340 浏览 1 评论 0原文

我今天遇到了一个奇怪的问题。我有一个 head.jsp (以 out.flush 结尾),它被其他页面包含。大多数页面都没有问题 out.flush();但我的一个页面在 jboss 4.2.2 GA 上因 IllegalStateException 失败。

我检查了相关的java文件ResponseFacade.java我认为。并看到问题是由于 if (isCommissed) 检查而发生的。

我刚刚从有问题的页面中删除了包含语句,它现在正在工作。 但问题是;为什么其他页面没有这个页面的问题而只有一个页面有问题?

或者如果 jsp 文件被其他页面包含。我需要在这个包含的页面中使用 out.flush() 吗?

I had a weird problem today. I have a head.jsp ( ending with out.flush ) which is being included by other pages. most of the pages doesn't have problem with this out.flush(); but one of my page is failing with IllegalStateException on jboss 4.2.2 GA.

I checked the related java file ResponseFacade.java I think. And see that problem occurs because of if (isCommitted) check.

I just removed the include statement from my problemmatic page and it is working now.
But the question is; why the other pages does not have problem with this page while the only one page has ?

or if a jsp file is being included by other pages. do I need to out.flush() in this included pages ?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

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

发布评论

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

评论(4

乖不如嘢 2024-12-31 04:03:48

当您使用flush()时,您将缓冲区的内容发送到客户端,然后清空缓冲区。
这没有什么不好的做法,您可以根据需要多次冲水。

请记住,JSP 页面的第一个 flash() 也将发送 HTTP HEADER,并且缓冲区被标记为已提交(状态 -> isComfilled)。
含义:此时您无法再发送 HTTP HEADER(例如 page_forward、cookie)。

很可能您试图在flush()完成后(在包含之后)在页面中发送一些HTTP HEADER。

When you flush() you send the content of the buffer to the client and then empty the buffer.
There is no bad practice in that, you can flush as many times as you need.

Just remember that the 1st flush() of a JSP page will send also the HTTP HEADERs, and the buffer is marked as committed (status -> isCommitted).
Meaning: at this point you can no more send HTTP HEADERs (like eg page_forward, cookies).

Chances are that you are trying to send some HTTP HEADER in the page after the flush() has been done (after the include).

阳光的暖冬 2024-12-31 04:03:48

这是唯一对我有用的方法(JSP over Tomcat/Apache)。

Main.jsp

<jsp:include page="flush.jsp" flush="true" />

Flush.jsp(空白)

<%
%>

This is the only method that worked for me (JSP over Tomcat/Apache).

Main.jsp

<jsp:include page="flush.jsp" flush="true" />

Flush.jsp (blank)

<%
%>
清秋悲枫 2024-12-31 04:03:47

当然,您的 Web 容器会在需要时刷新响应的输出流。您不需要任何调用来刷新。顺便说一句,JSP 中的 Java 代码无论如何都是不好的做法。

Your web container will of course flush the response's output stream when it needs to. You don't need any call to flush. BTW, Java code in JSP is bad practice anyway.

时间海 2024-12-31 04:03:47

我没有相同的设置,但遇到了类似的问题。

<% out.flush(); %> 在我的 jsp 中, 不再工作。未包含指定的页面。

我通过使用 <%@ include file="abc.jsp" %> 解决了这个问题

希望这会有所帮助。

I don't have the same setup but had a similar problem.

With <% out.flush(); %> in my jsp, <jsp:include page="abc.jsp" /> wasn't working any more. The specified page was not included.

I solved it by using <%@ include file="abc.jsp" %>

Hope this helps.

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