一次临时参与一个项目的上线前的压力测试工作,当模拟高并发请求后台servlet的时候,后台报错:
org.jboss.resteasy.spi.UnhandledException: Response is committed, can't handle exception
Caused by: java.lang.IllegalStateException: getWriter() has already been called for this response
网上说应该将 getWriter() 改成 outputStream() ,改成后又报错:
java.io.CharConversionException: Not an ISO 8859-1 character
后面又有人说加上 reset() , 改成后还报错:
java.lang.IllegalStateException: Cannot call reset() after response has been committed
决定从代码的角度找问题,发现写此代码的人,将 request 和 response 设置成了类的全局变量;
protected HttpServletRequest _request;
protected HttpServletResponse _response;
public void setServletRequest(HttpServletRequest request) throws UnsupportedEncodingException {
this._request = request;
request.setCharacterEncodi