`
xuenianliang
  • 浏览: 540 次
文章分类
社区版块
存档分类
最新评论

异常IllegalStateException: Cannot forward after response has been committe

    博客分类:
  • java
阅读更多

异常信息

java.lang.IllegalStateException: Cannot forward after response has been committed
    at org.apache.catalina.core.ApplicationDispatcher.doForward(ApplicationDispatcher.java:328)
    at org.apache.catalina.core.ApplicationDispatcher.forward(ApplicationDispatcher.java:318)
    at com.xue.chapter1.HelloServlet.doGet(HelloServlet.java:28)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:622)
    at javax.servlet.http.HttpServlet.service(HttpServlet.java:729)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:292)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
    at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter(ApplicationFilterChain.java:240)
    at org.apache.catalina.core.ApplicationFilterChain.doFilter(ApplicationFilterChain.java:207)
    at org.apache.catalina.core.StandardWrapperValve.invoke(StandardWrapperValve.java:212)
    at org.apache.catalina.core.StandardContextValve.invoke(StandardContextValve.java:106)
    at org.apache.catalina.authenticator.AuthenticatorBase.invoke(AuthenticatorBase.java:502)
    at org.apache.catalina.core.StandardHostValve.invoke(StandardHostValve.java:141)
    at org.apache.catalina.valves.ErrorReportValve.invoke(ErrorReportValve.java:79)
    at org.apache.catalina.valves.AbstractAccessLogValve.invoke(AbstractAccessLogValve.java:616)
    at org.apache.catalina.core.StandardEngineValve.invoke(StandardEngineValve.java:88)
    at org.apache.catalina.connector.CoyoteAdapter.service(CoyoteAdapter.java:528)
    at org.apache.coyote.http11.AbstractHttp11Processor.process(AbstractHttp11Processor.java:1099)
    at org.apache.coyote.AbstractProtocol$AbstractConnectionHandler.process(AbstractProtocol.java:672)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.doRun(NioEndpoint.java:1520)
    at org.apache.tomcat.util.net.NioEndpoint$SocketProcessor.run(NioEndpoint.java:1476)
    at java.util.concurrent.ThreadPoolExecutor.runWorker(Unknown Source)
    at java.util.concurrent.ThreadPoolExecutor$Worker.run(Unknown Source)
    at org.apache.tomcat.util.threads.TaskThread$WrappingRunnable.run(TaskThread.java:61)
    at java.lang.Thread.run(Unknown Source)

 

 

后台代码:

 @WebServlet("/hello")
public class HelloServlet extends HttpServlet {

    @Override
    protected void doGet(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        super.doGet(req, resp); // 请注视掉此行。
        DateFormat dateFormat = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        String currentTime = dateFormat.format(new Date());
        req.setAttribute("currentTime", currentTime);
        req.getRequestDispatcher("/WEB-INF/jsp/hello.jsp").forward(req, resp);
    }

    @Override
    protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
        // TODO Auto-generated method stub
        super.doPost(req, resp);
    }

}

 

 前台代码

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Hello, Servlet 3.0</title>
</head>
<body>

<!--注释掉servlet的super就可以访问到了-->
<h2>当前时间:${currentTime}</h2>
</body>
</html>

 

关于其他博客中转发或重定向后增加return或增加jsp容量的方法尝试未成功。

 

 

此文只是记录一个问题过程,切勿较真。

分享到:
评论

相关推荐

    关于IllegalStateException: The specified child already has a parent.

    IllegalStateException: The specified child already has a parent.我的博客中有文章讲解

    java.lang.IllegalStateException: getOutputStream() has already解决办法

    纠结了半天的 java.lang.IllegalStateException: getOutputStream() has already。这个问题困扰了半天,在网上查阅了大量资料 出这个错误一般就是下面2个.....

    Java异常之—-Caused by: java.lang.IllegalStateException: Method has too many Body parameters

    异常:Caused by: java.lang.IllegalStateException: Method has too many Body parameters Caused by: java.lang.IllegalStateException: Method has too many Body parameters: public abstract ...

    java.lang.IllegalStateException: OutputStream already obtain

    标题 "java.lang.IllegalStateException: OutputStream already obtain" 涉及到的是Java编程中的一个常见错误,特别是当处理I/O流时。这个异常通常在尝试获取已经存在的OutputStream实例时抛出,表明该输出流已经被...

    ListView后台更新报错:java.lang.IllegalStateException

    java.lang.IllegalStateException: The content of the adapter has changed but ListView did not receive a notification. Make sure the content of your adapter is not modified from a background thread, but...

    powerbuilder

    ### PowerBuilder 中从 Excel 导入数据到 DataWindow 的实现方法 #### 标题解析: 在 PowerBuilder 开发环境中,经常需要将外部数据源(如 Excel 文件)中的数据导入到程序内部的数据展示组件(DataWindow)中进行...

    Android异常 java.lang.IllegalStateException解决方法

    1. java.lang.IllegalStateException: No wrapped connection. 2.java.lang.IllegalStateException: Adapter is detached. 原因: 1.单线程一次执行一个请求可以正常执行,如果使用多线程,同时执行多个请求时就会...

    action-buffer:提供了在处理后台任务时避免片段过渡期间出现 IllegalStateException 的示例

    这个存储库提供了一种在处理片段传输和后台任务时避免“java.lang.IllegalStateException:Can not perform this action after onSaveInstanceState”的方法。 您可以在的非常权威的阅读有关该问题和可能的解决方案...

    spark 核心架包

    解决java.lang.IllegalStateException: unread block data的架包

    spring入门好教程

    此外,它提供了一种一致的数据访问方式,拥有统一的异常层次结构,简化了与JDBC、Hibernate、JDO等数据访问技术的交互。Spring的模型-视图-控制器(MVC)框架灵活易用,IoC与AOP的集成使得代码结构更加清晰。更重要...

    JSP三种跳转方式 超级好的范例

    java.lang.IllegalStateException: Can't sendRedirect() after data has been committed to the client. ``` 解决办法是在进行任何输出之前先检查是否需要重定向。 #### 二、`response.setHeader("Location", "")`...

    asm5.0.jar

    Cause: java.lang.IllegalStateException: Cannot enable lazy loading because CGLIB is not available. Add CGLIB to your classpath.:java.lang.IncompatibleClassChangeError: class ...

    Android异常处理

    ### Android异常处理详解 #### 一、异常机制概述 异常机制是编程语言中用于处理运行时错误的关键技术之一。在Android开发中,由于其基于Java语言,因此异常处理机制也遵循Java的标准。本文旨在深入探讨Android开发...

    xfire访问webservice客户端用到的jar包

    在Java开发中,Web服务(Web Service)是一种标准的接口,允许不同系统之间进行通信,而XFire是早年流行的一款用于构建和消费Web服务的开源框架。它使用SOAP(简单对象访问协议)和XML(可扩展标记语言)作为基础,...

    tomcat-redis-session-manager-tomcat-7

    tomcat-redis-session 共享 异常解决:Race condition encountered...java.lang.IllegalStateException: Race condition encountered: attempted to load session[xxx] which has been created but not yet serialized.

    Jnative1.4_java调用动态库所需jar

    Java是一种高级编程语言,通常用于开发跨平台的应用程序。然而,有时我们可能需要在Java程序中调用操作系统底层的动态链接库(DLLs on Windows,SOs on Linux,dylibs on macOS),以便利用C、C++等语言编写的高性能...

    oop object , for apple ios developer

    ### 面向对象编程与Objective-C:苹果iOS开发者指南 #### 一、概述 面向对象编程(Object-Oriented Programming, OOP)是一种广泛应用于软件开发中的编程范式,它将程序设计围绕“对象”进行组织。...

    jacob使用说明终极吐血版

    // 调用可能抛出异常的代码 } catch (ComException e) { int hresult = e.getHresult(); String description = e.getDescription(); // 处理错误... } ``` ## 7. 多线程和线程安全 Jacob支持在多线程环境中...

Global site tag (gtag.js) - Google Analytics