aspose file tools*
The moose likes JSP and the fly likes How to Open Excel file from JSP page. Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Java » JSP
Bookmark "How to Open Excel file from JSP page." Watch "How to Open Excel file from JSP page." New topic
Author

How to Open Excel file from JSP page.

Sheetal Patil
Greenhorn

Joined: Mar 27, 2005
Posts: 5
Hi All,

I am using POI API to create Excel file to export JSP page data. I am able to create file but if I click on a link to open the file it shows some garbage data in browser. Can anyone please help me to solve this problem asap.

Thanks in advance,

Sheetal
Bear Bibeault
Author and ninkuma
Marshal

Joined: Jan 10, 2002
Posts: 61419
    
  67

JSP is a poor technology choice for delivering such data. You should be serving such data from a servlet. It may be that you're not creating the data correctly, or it may be that the JSP mechansism, which assume that you are delivering text data such as HTML pages, is getting in your way.
[ September 12, 2005: Message edited by: Bear Bibeault ]

[Asking smart questions] [Bear's FrontMan] [About Bear] [Books by Bear]
Sheetal Patil
Greenhorn

Joined: Mar 27, 2005
Posts: 5
Hi

Actually I am getting data from Bean which I displays on my JSP Page. I want to export that bean data to excel. I am using poi api to create excel file in JSP. I am able to create that. But the problem is I have one lonk to export data which should open that excel file. But I can't open that file.

Thanks
Sheetal
Vikas Bhatia
Greenhorn

Joined: Mar 22, 2005
Posts: 17
Originally posted by Sheetal Patil:
Hi

Actually I am getting data from Bean which I displays on my JSP Page. I want to export that bean data to excel. I am using poi api to create excel file in JSP. I am able to create that. But the problem is I have one lonk to export data which should open that excel file. But I can't open that file.

Thanks
Sheetal



It almost looks like that the content-type is not being set properly? Would you mind sharing the code?
babu hiran
Greenhorn

Joined: Jun 04, 2005
Posts: 12
this is how an excel sheet can be done in jsp
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.0 Transitional//EN">
<HTML>
<HEAD>
<TITLE>Comparing Apples and Oranges</TITLE>
<LINK REL=STYLESHEET
HREF="JSP-Styles.css"
TYPE="text/css">
</HEAD>
<BODY>
<CENTER>
<H2>Comparing Apples and Oranges</H2>
<%
String format = request.getParameter("format");
if ((format != null) && (format.equals("excel"))) {
response.setContentType("application/vnd.ms-excel");
}
%>
<TABLE BORDER=1>
<TR><TH></TH><TH>Apples<TH>Oranges
<TR><TH>First Quarter<TD>2307<TD>4706
<TR><TH>Second Quarter<TD>2982<TD>5104
<TR><TH>Third Quarter<TD>3011<TD>5220
<TR><TH>Fourth Quarter<TD>3055<TD>5287
</TABLE>
</CENTER>
</BODY>
</HTML>
Ben Souther
Sheriff

Joined: Dec 11, 2004
Posts: 13410

narayana,

Sheetal mentioned earlier in the thread that he's using POI to build a file in MS-Excel format which he plans on streaming to the browser.


Java API J2EE API Servlet Spec JSP Spec How to ask a question... Simple Servlet Examples jsonf
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: How to Open Excel file from JSP page.