servlet 重定向问题
1.jsp页面
<body>
<iframe frameborder="0" src="include/top.html" width="100%" height="189px" scrolling="no" name="iframetop"></iframe>
<iframe frameborder="0" src="index.action?method=index" width="100%" height="1320px" scrolling="no" name="iframecenter" ></iframe>
<iframe frameborder="0" src="include/bottom.html" width="100%" height="120px" scrolling="no" name="iframecenter" ></iframe>
</body>
2.servlet跳转
@Override
protected void service(HttpServletRequest req, HttpServletResponse resp)
throws
ServletException,
IOException {
req.setCharacterEncoding("UTF-8");
resp.setCharacterEncoding("UTF-8");
String method = req.getParameter("method");
if(method != null){
System.out.println(method);
this.index(req, resp);
}else{
}
}
protected void index(HttpServletRequest req, HttpServletResponse resp)
throws ServletException, IOException {
super.service(req, resp);
List tzxxlist = tzxxservice.findAll();
req.setAttribute("tzxxlist", tzxxlist);
req.getRequestDispatcher("include/center.jsp").forward(req, resp);
return;
}
3.报错
HTTP Status 500 - Cannot forward after response has been committed
--------------------------------------------------------------------------------
type Exception report
message Cannot forward after response has been committed
description The server encountered an internal error that prevented it from fulfilling this request.
exception
java.lang.IllegalStateException: Cannot forward after response has been committed
com.jztjs.www.servlet.IndexServlet.index(IndexServlet.java:77)
com.jztjs.www.servlet.IndexServlet.service(IndexServlet.java:47)
javax.servlet.http.HttpServlet.service(HttpServlet.java:728)
note The full stack trace of the root cause is available in the Apache Tomcat/7.0.33 logs.
------解决方案--------------------用绝对路径试试,再有BUG跑一下,看看这个代码有没有重复跑
------解决方案--------------------不需要调用super.service(req, resp);
------解决方案--------------------java.lang.
IllegalStateException: Cannot forward after respons