记录-servlet配置过程中的java.lang.IllegalStateException错误

错误代码:


	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
		super.doGet(req, resp);
        	doPost(req, resp);
	}


	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
			super.doPost(req, resp);
			//想客户端输出内容
			PrintWriter writer=resp.getWriter();
			writer.println("hello TestServlet!");
			writer.close();		
	}
java.lang.IllegalStateException: Cannot call sendError() after the response has been committed

	org.apache.catalina.connector.ResponseFacade.sendError(ResponseFacade.java:450)
	javax.servlet.http.HttpServlet.doPost(HttpServlet.java:315)
	cn.news.servlet.TestServlet.doPost(TestServlet.java:36)
	cn.news.servlet.TestServlet.doGet(TestServlet.java:29)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:624)
	javax.servlet.http.HttpServlet.service(HttpServlet.java:731)
	org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)

正确代码:

	@Override
	protected void doGet(HttpServletRequest req, HttpServletResponse resp)
		throws ServletException, IOException {
        	doPost(req, resp);
	}


	@Override
	protected void doPost(HttpServletRequest req, HttpServletResponse resp)
			throws ServletException, IOException {
			//想客户端输出内容
			PrintWriter writer=resp.getWriter();
			writer.println("hello TestServlet!");
			writer.close();		
	}

参考解析:https://blog.csdn.net/u012377333/article/details/72263686


你可能感兴趣的:(记录-servlet配置过程中的java.lang.IllegalStateException错误)