0

Servlet receives unexpected IllegalStateException: Writer already obtained

asked 2011-06-22 06:18:08 +0800

oshqair gravatar image oshqair
9 1

Dear All,
I have to view a jasper report inside zul page.
I am using jasper reports applet version 4.0.0.I have included the applet tag <n:applet> inside zul page to view a jasper report using embedded viewer class, this applet calls a servlet that gets the jasperPrint object from the Http Session and writes back the result as application/octet-stream.

The report appears with no exceptions. But when I make any action after report preview like select or save etc…, the exception are thrown:
1. java.lang.IllegalStateException: Cannot reset buffer after response has been committed
2. Servlet receives unexpected IllegalStateException: Writer already obtained

Note that it’s working successfully with tomcat application server, and no exceptions happen, the exception only appears when deploying in websphere application server ver. 6.1 or 7.0.

On the other hand, when deploying the same servlet outside the ZK project, it works fine with all servers types mentioned above.

sample of servlet code...

public void service(HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {
		JasperPrint jasperPrint = (JasperPrint) request.getSession().getAttribute(ImageServlet.DEFAULT_JASPER_PRINT_SESSION_ATTRIBUTE);
		
		if (jasperPrint != null) {
			ServletOutputStream ouputStream = null;
			ObjectOutputStream oos = null;
			
			try {
				response.setContentType("application/octet-stream");
				ouputStream = response.getOutputStream();
				oos = new ObjectOutputStream(ouputStream);
				oos.writeObject(jasperPrint);
				oos.flush();
				ouputStream.flush();
				
			} catch(Exception e) {
				e.printStackTrace();
			} finally {
				oos.close();
				ouputStream.close();
			}
		}
	}

Any help will be appreciated.

Thank You

delete flag offensive retag edit

1 Reply

Sort by » oldest newest

answered 2011-07-10 23:06:07 +0800

RyanWu gravatar image RyanWu
533 2
about.me/flyworld

i guess these exceptions are caused by the buffer size, in other words, the default buffer were fulled and has been submitted to client.

you can try extend ServletOutputStream and enlarge the buffer.

link publish delete flag offensive edit
Your reply
Please start posting your answer anonymously - your answer will be saved within the current session and published after you log in or create a new account. Please try to give a substantial answer, for discussions, please use comments and please do remember to vote (after you log in)!

[hide preview]

Question tools

Follow

RSS

Stats

Asked: 2011-06-22 06:18:08 +0800

Seen: 1,245 times

Last updated: Jul 10 '11

Support Options
  • Email Support
  • Training
  • Consulting
  • Outsourcing
Learn More