We may use the output stream of the page when we are doing file upload or download, or filtering.
For example, use in action:
Response.reset ();
Response.setcontenttype ("application/vnd.ms-excel");
OutputStream OS = Response.getoutputstream ();
Throw exception: Java.lang.IllegalStateException
Cause Analysis:
This is a out.write ("") in the servlet code generated by the Web container, which conflicts with the Response.getoutputstream () called in the JSP.
That is, the servlet specification description, cannot call Response.getoutputstream (), and call Response.getwriter (), regardless of which one is called first, should be thrown at the second time of the call IllegalStateException,
Because in the JSP, the out variable is obtained through the Response.getwriter, in the program both uses the Response.getoutputstream, but also uses the out variable, therefore appears above error.
French one: In the JSP file, add the following two sentences
<%
Out.clear ();
out = Pagecontext.pushbody ();
%>
Defects of this method:
Many development projects are not JSP frontend, such as freemarker,velocity, etc.
The "Response.getoutputstream ()" That caused the problem was not written in the JSP, but in the servlet/action.
Law two: In action, do not return to the specific result file, but return null
return SUCCESS;
return null;
Java.lang.IllegalStateException Exceptions: Simple analysis and simple solutions