This week's giveaway is in the Android forum.
We're giving away four copies of Android Security Essentials Live Lessons and have Godfrey Nolan on-line!
See this thread for details.
The moose likes JSP and the fly likes Open excel in JSP Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login

Win a copy of Android Security Essentials Live Lessons this week in the Android forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "Open excel in JSP" Watch "Open excel in JSP" New topic

Open excel in JSP

Rakesh Gadre
Ranch Hand

Joined: Feb 22, 2003
Posts: 47
I am trying to display an excel file to the user. In the jsp file, the code is as under:

FileInputStream fileStream = new FileInputStream (fileNameWithPath);
int numberOfBytes = fileStream.available ();
byte contents [] = new byte [numberOfBytes]; (contents);
ServletOutputStream sout = response.getOutputStream();
response.setHeader("Content-Disposition","inline; filename=\"" + onlyFileName + "\";");

sout.write (contents);

Now, the problem is as under:

The server does not have MS office(Excel) installed on it. If I try to set the content type as ms-excel, it does not recognises it and what i get is junk code. Is there any way to read the excel without having MS office(Excel) installed on the server ?

Thanks in advance

Paul Sturrock

Joined: Apr 14, 2004
Posts: 10336

Don't bother trying to stream it through your servlet. Just add a link to it in a page and when the user clicks on the link whatever their browser/OS is configured to do with .xls files will happen.

JavaRanch FAQ HowToAskQuestionsOnJavaRanch
Sahil Singh
Ranch Hand

Joined: Sep 03, 2003
Posts: 41
Hi Paul,
I am trying to do something similar.

I have a JSP page which gets data from the DB.
I need to display the returned data displayed in an Excel sheet.
Have put the following code at the start of the JSP page.
<%@ page contentType = "application/" %>
<% response.setContentType("application/"); %>

It does open the excel sheet , but the sheet is empty.
There is no data.

Please guide.

Consider Paul's rocket mass heater.
subject: Open excel in JSP
Similar Threads
Excel file is corrupted when i download it
Junk characters while reading an excel file
while opening csv file, dialog box opens twice
Junk characters while reading excel file
OPEN/SAVE popoup box comes twice