设置page指令中buffer="0kb",转发标签不起作用了
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"
buffer="0kb"%>
<%
%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
<script src="js/jquery-1.8.3.js" type="text/javascript" charset="utf-8"></script>
</head>
<body>
<form action="forward1.jsp">
<input type="text" value="123" name="str1"/>
<button>提交</button>
</form>
<%
out.write("aaaaaaaa");
out.write("</br>");
String s1 = request.getParameter("str1");
System.out.print("s1:"+s1);
if(s1!=null){
if("中文".equals(s1)){
out.write("bbbb");
%>
<jsp:forward page="forward2.jsp"></jsp:forward>
<%} else { %>
<jsp:forward page="forward3.jsp"></jsp:forward>
<%}} %>
</body>
<script type="text/javascript">
</script>
</html>
- ## 结果如下,forward2,forward3完全没有转发
![图片说明](https://img-ask.csdn.net/upload/202008/30/1598727806_929271.png)
没有转发,并且会出现以下异常
八月 30, 2020 10:40:45 上午 org.apache.catalina.core.StandardWrapperValve invoke
严重: Servlet.service() for servlet [jsp] in context with path [/JavaWeb-JSP_EL_JSTL] threw exception [An exception occurred processing JSP page [/forward1.jsp] at line [25]
22: if(s1!=null){
23: if("中文".equals(s1)){
24: %>
25: <jsp:forward page="forward2.jsp"></jsp:forward>
26:
27: <%} else { %>
28: <jsp:forward page="forward3.jsp"></jsp:forward>
Stacktrace:] with root cause
java.lang.IllegalStateException: Illegal to clear() when buffer size == 0
at org.apache.jasper.runtime.JspWriterImpl.clear(JspWriterImpl.java:143)
at org.apache.jasper.runtime.PageContextImpl.doForward(PageContextImpl.java:721)
at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:712)
at org.apache.jsp.forward1_jsp._jspService(forward1_jsp.java:138)
at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:70)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:443)
at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:386)
at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:330)
at javax.servlet.http.HttpServlet.service(HttpServlet.java:742)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:231)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:193)
at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:166)
at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:199)
at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:96)
at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:140)
at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:81)
at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:650)
at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:87)
at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:342)
at org.apache.coyote.http11.Http11Processor.service(Http11Processor.java:803)
at org.apache.coyote.AbstractProcessorLight.process(AbstractProcessorLight.java:66)
at org.apache.coyote.AbstractProtocol$ConnectionHandler.process(AbstractProtocol.java:790)
at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1459)
at org.apache.tomcat.util.net.SocketProcessorBase.run(SocketProcessorBase.java:49)
at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
at java.lang.Thread.run(Unknown Source)
- ## 而如果将buffer设置为默认以后,就会出现一下状况:转发成功(转发到forward3.jsp)
![图片说明](https://img-ask.csdn.net/upload/202008/30/1598727941_867408.png)