java.lang.IllegalStateException:使用jsp:include包含HTML文件时,在提交响应后无法转发 [英] java.lang.IllegalStateException: Cannot forward after response has been committed while including HTML files using jsp:include
问题描述
当<jsp:include>
用于包含HTML文件时DispatcherServlet
正在抛出
When <jsp:include>
is used for including HTML file DispatcherServlet
is throwing
java.lang.IllegalStateException: Cannot forward after response has been committed
我有一个servlet:
I have one servlet:
<servlet-mapping>
<servlet-name>web</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
在其中,我启用了Spring MVC批注,并为没有控制器的JSP文件提供了处理程序映射和适配器(将旧的webapp转换为Spring).并且我已经在该Servlet中启用了DefaultServletHttpRequestHandler
.
In it, I have enabled Spring MVC annotations and have handler mapping and adapter for JSP files without controllers (converting old webapp to Spring). And I have enabled DefaultServletHttpRequestHandler
in this Servlet.
有什么想法在包含html文件时如何避免IllegalStateException
?
Any idea how to avoid that IllegalStateException
when including html files?
推荐答案
因此,如果让spring处理所有html文件,则由于jsp:include
上它总是会失败.
So if you let spring handle all html files, it will always fail on jsp:include
because spring cannot handle html includes.
对我而言,最好的解决方法是将html文件保留在默认servlet上.
Best way around this for me was to leave html files on default servlet.
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.html</url-pattern>
<url-pattern>*.htm</url-pattern>
</servlet-mapping>
并在DispatcherServlet
上保持静止.
<servlet>
<servlet-name>web</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>web</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
这绝对不是最佳解决方案,但是直到我将所有jsps(约1000个)转换为mvc和类似tile的东西,这才是我看到它工作的唯一方法.
This is definitely not a best solution, but until I convert all jsps (around 1000 of them) to mvc and something like tiles this is the only way I can see it working.
这篇关于java.lang.IllegalStateException:使用jsp:include包含HTML文件时,在提交响应后无法转发的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!