无法转发.响应已提交.错误 [英] Cannot forward.Response already committed. Error
本文介绍了无法转发.响应已提交.错误的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我正在使用以下命令从jsp调用servlet:
I am calling a servlet from jsp using
//My servlet code is:
public void doGet(HttpServletRequest request, HttpServletResponse response)
{
String template="test";
abcViewBean punchOutCan = new abcViewBean();
punchOutCan.setPunchOutCanonicalRes(template);
try {
request.getRequestDispatcher("/PunchOutCanonicalError.jsp").forward(request,response);
} catch (ServletException e) {
// TODO Auto-generated catch block
e.printStackTrace();
} catch (IOException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}
我的JSP代码是:
<jsp:include page="/PunchOutCanonicalServlet" flush="true"/>
<c:out value="${punchOutCan.punchOutCanonicalRes}" />
请提出建议,如何摆脱这种情况.
Please suggest, how to get rid of this.
推荐答案
因为要在JSP中导入响应,所以从servlet的doGet
中排除(删除)此语句.
Exclude (remove) this statement from doGet
of servlet because you're importing the response in JSPs.
request.getRequestDispatcher("/PunchOutCanonicalError.jsp")
.forward(request,response);
doGet必须为:
@Override
public void doGet(HttpServletRequest request,
HttpServletResponse response)
throws ServletException,IOException{
String template="test";
abcViewBean punchOutCan = new abcViewBean();
punchOutCan.setPunchOutCanonicalRes(template);
//You can push the bean object into request via setAttribute
//e.g
//request.setAttribute("punchOutCan",punchOutCan);
}
还有JSP代码,
<jsp:include page="/PunchOutCanonicalServlet" flush="true"/>
<c:out value="${punchOutCan.punchOutCanonicalRes}" />
这篇关于无法转发.响应已提交.错误的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文