File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
The moose likes Servlets and the fly likes XLS opening junk Using Servlets Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Java » Servlets
Bookmark "XLS opening junk Using Servlets" Watch "XLS opening junk Using Servlets" New topic

XLS opening junk Using Servlets

Vivg Gupta

Joined: May 04, 2006
Posts: 16

We are trying to open excel files using a servlet. The code is hosted on Websphere Portal Server. The servlet accepts request from a jsp file and opens the requested excel file from the required location. There are two WPS servers having their individual URLs and there is one clustered URL for these two servers.

Now the problem is that for all the excels which are less than 33KB in size, we are getting junk data when we try to open the same from the clustered URL. But the same excel opens up perfectly fine from the individual server URLs. Excels which are more than 33 kb are not giving any problem anywhere. The code we are using is:

URL url = new URL(excelLocation);
URLConnection urlcon = url.openConnection();
res.setContentType( urlcon.getContentType() ); // MIME type

//Using Buffered Stream for reading/writing.

bis = new BufferedInputStream(url.openStream());
ServletOutputStream out = res.getOutputStream();

bos = new BufferedOutputStream(out);
byte[] buff = new byte[1024];
int bytesRead;

// Simple read/write loop.
while(-1 != (bytesRead =, 0, buff.length))) {
bos.write(buff, 0, bytesRead);

This is really a very weird situation. Any help would be really commendable.

Also, we are getting the following warning in the logs:

00000087 ServletWrappe E SRVE0014E: Uncaught service() exception root cause /checkthis.jsp: SRVE0199E: OutputStream already obtained
[6/10/07 3:02:18:460 EDT] 00000087 LocalTranCoor E WLTC0017E: Resources rolled back due to setRollbackOnly() being called.
[6/10/07 3:02:18:462 EDT] 00000087 WebApp E SRVE0026E: [Servlet Error]-[/checkthis.jsp]: java.lang.IllegalStateException: SRVE0199E: OutputStream already obtained

William Brogden
Author and all-around good cowpoke

Joined: Mar 22, 2000
Posts: 13036
Uncaught service() exception root cause /checkthis.jsp: SRVE0199E: OutputStream already obtained

The reason is right in front of you - the JSP has already obtained the output stream for character output because thats what JSP do.

You need to put your code in a servlet where there is no automatic opening of the output stream.

I agree. Here's the link:
subject: XLS opening junk Using Servlets
It's not a secret anymore!