정수리
309
2015-08-10 11:29:15
0
1941

java.lang.IllegalStateException: Cannot forward after response has been committed


현재 장바구니를 구현중입니다. 어제 상세페이지에서 장바구니를 클릭하면 null값으로 값이 넘어오다는 질문을 올렸었습니다. 다행히 댓글로 도움을 주셔서 해결은 되었습니다!! 댓글 작성해주신 분들에게 정말 감사합니다 ㅜ.ㅜ 값은 정상적으로 넘어오고 db에 저장까지됩니다!!!

그런데 새로운 문제가 발생하였습니다...ㅜ.ㅜ db에 값이 들어가고 장바구니 리스트를 보여줘야 되는데

jsp 페이지로 넘어가지 않습니다.. db에 저장이 되고 controller에서 basketListaction까지는 되는 것같은데

jsp페이지로 넘어가지 않고 오류가 뜹니다. 

java.lang.IllegalStateException: Cannot forward after response has been committed 가 뜹니다 ㅜ.ㅜ

오류를 따라 가면 색깔있는 곳에서 문제가 발생하는 것같습니다.

여러 정보를 따르면 controller에서 doget, gopost에서 doprocess를 요청하는 메서드를 지우라고 해서 지우면 장바구니에 정보가 들어가지 않습니다....ㅜ.ㅜ 무엇이 문제 일까요 ??

오류

java.lang.IllegalStateException: Cannot forward after response has been committed
	at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:348)
	at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:338)
	at jnmk.basket.action.BasketFrontController.doProcess(BasketFrontController.java:56)
	at jnmk.basket.action.BasketFrontController.doGet(BasketFrontController.java:63)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
	at javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:303)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
	at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:241)
	at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:208)
	at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:220)
	at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:122)
	at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:505)
	at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:170)
	at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:103)
	at org.apache.catalina.valves.AccessLogValve.invoke(AccessLogValve.java:957)
	at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:116)
	at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:423)
	at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1079)
	at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:620)
	at org.apache.tomcat.util.net.JIoEndpoint$SocketProcessor.run(JIoEndpoint.java:318)
	at java.util.concurrent.ThreadPoolExecutor.runWorker(ThreadPoolExecutor.java:1142)
	at java.util.concurrent.ThreadPoolExecutor$Worker.run(ThreadPoolExecutor.java:617)
	at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
	at java.lang.Thread.run(Thread.java:745)

장바구니 리스트액션 클래스

package jnmk.basket.action;

import java.io.PrintWriter;
import java.util.ArrayList;
import java.util.List;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

import jnmk.basket.action.Action;
import jnmk.basket.action.ActionForward;
import jnmk.basket.db.BasketDAO;

public class BasketListAction implements Action{
	public ActionForward execute(HttpServletRequest request,HttpServletResponse response)
	throws Exception{
		BasketDAO basketdao=new BasketDAO();
		HttpSession session=request.getSession();
		String email=(String)session.getAttribute("email");
		
		if(email==null){
			PrintWriter out=response.getWriter();
			out.println("<script>");
			out.println("history.go(-1);");
			out.println("</script>");
			out.close();
		}
		
		Vector vector = basketdao.getBasketList(email);
		List basketlist=(ArrayList)vector.get(0);
		List goodslist=(ArrayList)vector.get(1);
		
		request.setAttribute("basketlist", basketlist);
		request.setAttribute("goodslist", goodslist);
		
		ActionForward forward=new ActionForward();
		forward.setRedirect(false);
		forward.setPath("goods_basket.jsp");
		
		return forward;
	}
}

FrontController 

package jnmk.basket.action;

import java.io.IOException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
 * Servlet implementation class BasketFrontController
 */
@WebServlet("*.ba")
public class BasketFrontController extends javax.servlet.http.HttpServlet
		implements javax.servlet.Servlet {
	static final long serialVersionUID = 1L;

	protected void doProcess(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		String RequestURI = request.getRequestURI();
		String contextPath = request.getContextPath();
		String command = RequestURI.substring(contextPath.length());
		ActionForward forward = null;
		Action action = null;

		if (command.equals("/BasketList.ba")) {
				System.out.println("리스트보여주자");
				action = new BasketListAction();
			try {
				forward = action.execute(request, response);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} else if (command.equals("/BasketAdd.ba")) {
			System.out.println("장바구니추가");
			action = new BasketAddAction();
			try {
				forward = action.execute(request, response);
			} catch (Exception e) {
				e.printStackTrace();
			}
		} /*else if (command.equals("/BasketDelete.ba")) {
			action = new BasketDeleteAction();
			try {
				forward = action.execute(request, response);
			} catch (Exception e) {
				e.printStackTrace();
			}
		}*/
		if (forward != null) {
			if (forward.isRedirect()) {
				response.sendRedirect(forward.getPath());
			} else {
				RequestDispatcher dispatcher = request.getRequestDispatcher(forward.getPath());
				dispatcher.forward(request, response);
			}
		}
	}

	protected void doGet(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}

	protected void doPost(HttpServletRequest request,
			HttpServletResponse response) throws ServletException, IOException {
		doProcess(request, response);
	}
}


0
  • 답변 0

  • 로그인을 하시면 답변을 등록할 수 있습니다.