我有一個jsp。它在jsp負載上調用一個servlet並將結果顯示在如下所示的相同jsp中。從servlet調用jsp時獲取異常?
Some.jsp
<html>
<jsp:include page="/HelloWorld"/>
<%Iterator itr;%>
<% List data= (List)request.getAttribute("results");
for (itr=data.iterator(); itr.hasNext();)
{
%>
<TABLE align="center" cellpadding="15" border="1" style="background-color: #ffffcc;">
<TR>
<TD align="center"><%=itr.next()%></TD>
</TR>
</TABLE>
<%}%>
</body>
</html>
在servlet的我正在存儲請求的結果,並使用的RequestDispatcher調用JSP如下。
public class SomeServlet extends HttpServlet {
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,IOException{
List<String> list = new ArrayList<String>();
//some logic to populate list
request.setAttribute("results", list);
request.getRequestDispatcher("/WEB-INF/Some.jsp").forward(request, response);
}
}
但我正在逐漸例外之下,而在JSP中顯示結果:
java.io.IOException: Stream closed
at org.apache.jasper.runtime.JspWriterImpl.ensureOpen(JspWriterImpl.java:202)
at org.apache.jasper.runtime.JspWriterImpl.clearBuffer(JspWriterImpl.java:157)
請幫助我..
您應該在將請求轉發到JSP之後編寫返回信息 –