The server encountered an internal error () that prevented it from fulfilling this request

来源:互联网 发布:淘宝产品图片 编辑:程序博客网 时间:2024/05/22 23:09

为了测试:request.getReqestDispatcher("test02.jsp").forward(request,response);

写了个程序,一直出现如题异常,最终解决:

在调用它们之前,都不能有内容已经被实际输出到了客户端。如果缓冲区中已经有了一些内容,这些内容将被从缓冲区中清除。

因为myeclipse 自动生成的代码忘记删除,所以导致该错误。

api:

 

forward

void forward(ServletRequest request,             ServletResponse response)             throws ServletException,                    IOException
Forwards a request from a servlet to another resource (servlet, JSP file, or HTML file) on the server. This method allows one servlet to do preliminary processing of a request and another resource to generate the response.

For a RequestDispatcher obtained via getRequestDispatcher(), theServletRequest object has its path elements and parameters adjusted to match the path of the target resource.

forward should be called beforethe response has been committed to the client (before response body output has been flushed). If the response already has been committed, this method throws anIllegalStateException. Uncommitted output in the response buffer is automatically cleared before the forward.

The request and response parameters must be either the same objects as were passed to the calling servlet's service method or be subclasses of theServletRequestWrapper orServletResponseWrapper classes that wrap them.

Parameters:
request - a ServletRequest object that represents the request the client makes of the servlet
response - a ServletResponse object that represents the response the servlet returns to the client
Throws:
ServletException - if the target resource throws this exception
IOException - if the target resource throws this exception
IllegalStateException - if the response was already committed

原创粉丝点击