Hi,

In general, writing binary data from a JSP is not a good idea. JSPs are
meant to write character-based formats such as HTML or text. In addition,
you need to be very careful not to have any spurious newlines in your JSP,
for instance, this following code

<% @page import="some.package.Class" %>
<%
        // insert code to output HSSFWorkBook as Excel binary stream
%>

might already generate a corrupt Excel document in some servlet containers
beause of the newline after the <% @page  %> directive. This could be
avoided like this:

<% @page import="some.package.Class" %><%
        // insert code to output HSSFWorkBook as Excel binary stream
%>

but that makes your JSP code harder to read.

The fact that it will work in some servlet containers should, of course, not
be relied on. J2EE intends to be a platform-independent, container
implementation independent architecture. In your case, using a servlet seems
like a fine solution, since you don't seem to be using any JSP-features
(mixing of code and markup, taglibs, etc.) anyway.

Regards,
Frans

> -----Original Message-----
> From: Vytla, Aparna (GE Commercial Finance, NonGE)
> [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, February 15, 2005 5:44 PM
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> 
> I see some reason now.Could be the implemetation of output 
> stream to which we write out our workbook,is diffrent for 
> both versions in my container!! hence causing this wierd problem.
> 
> -----Original Message-----
> From: Sharma, Siddharth [mailto:[EMAIL PROTECTED]
> Sent: Tuesday, February 15, 2005 10:20 AM
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> 
> That is a fair comment.
> I am also vaguely aware of this behavior in IE.
> But I thought setting the content type explicitly overrode 
> this behavior.
> 
> Anyhow, as to using a servlet v/s a JSP, again comes down to container
> implementations. The request and response objects, even 
> though should be the
> same classes, could be of different types in servlets and 
> JSPs as long as
> they implement the HTTPServletRequest and HTTPServletResponse 
> interfaces
> respectively.
> Maybe in your container, they are different implementations 
> to support some
> vendor extension. (MAYBE!! Could easily be some other more 
> trivial reason).
> 
> As I said, your JSP worked fine when I ran it on my side (Websphere).
> 
> 
> 
> 
> -----Original Message-----
> From: [EMAIL PROTECTED]
> [mailto:[EMAIL PROTECTED] 
> Sent: Tuesday, February 15, 2005 9:54 AM
> To: [email protected]
> Subject: RE: Opening HSSF Workbook in Excel
> 
> (Totally off the top of my head)
> 
> could your browser have been making dodgy guesses at the filetype? I
> know I had a situation (in ASP) where naming my script 
> 'renderjpeg.aspx'
> didn't work - correct MIME type notwithstanding - but
> 'renderjpeg.jpg.aspx' worked fine.
> 
> So maybe you could've tried naming the JSP '.xls.jsp...'
> 
> What I experienced was documented dodgy behaviour in IE, 
> though I don't
> have the link for it right now.
> 
> 
> 
> -----Original Message-----
> From: Vytla, Aparna (GE Commercial Finance, NonGE)
> [mailto:[EMAIL PROTECTED] 
> Sent: 15 February 2005 14:49
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> 
> Hey,
>   Today i tried replacing my jsp with a servlet.It's working
> fine.Anyway,i don't see why it didn't work with the JSP.
> 
> Thanks guys.
> 
> -----Original Message-----
> From: Sharma, Siddharth [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 14, 2005 5:04 PM
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> 
> I copy-posted your code and ran it, it worked fine.
> Try setting the content length. Maybe your server is not setting the
> content length header, or something on those lines.
> 
> 
> -----Original Message-----
> From: Vytla, Aparna (GE Commercial Finance, NonGE)
> [mailto:[EMAIL PROTECTED] 
> Sent: Monday, February 14, 2005 4:54 PM
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> Tried this too.Nope.Still the same problem.
> 
> -----Original Message-----
> From: Sharma, Siddharth [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 14, 2005 4:36 PM
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> 
> Try doing this for all cells and see if this works.
> I am not sure if this will fix your problem though. But try it.
> 
> cell1_New.setCellType(HSSFCell.CELL_TYPE_STRING);
> 
> 
> -----Original Message-----
> From: Vytla, Aparna (GE Commercial Finance, NonGE)
> [mailto:[EMAIL PROTECTED] 
> Sent: Monday, February 14, 2005 4:28 PM
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> It seems it didn't refresh properly.Hence i saw some binary 
> data showing
> up on the browser window.I tried closing the browser and opened a new
> instance. Now,it opens up an Excel but some junk is being shown inside
> the excel. 
> 
> thanks,
> 
> 
> -----Original Message-----
> From: Sharma, Siddharth [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 14, 2005 4:18 PM
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> 
> Could you explain what you mean by "It is showing the output on the
> browser itself."?
> 
> 
> -----Original Message-----
> From: Vytla, Aparna (GE Commercial Finance, NonGE)
> [mailto:[EMAIL PROTECTED] 
> Sent: Monday, February 14, 2005 4:15 PM
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> Hi Siddharth,
>   Thanks for your quick response.I've tried that too.It is showing the
> output on the browser itself.Here is my sample jsp page.
> 
> <%@ page import = "java.util.*, java.text.*,
> javax.servlet.http.*,org.apache.poi.hssf.usermodel.*" %> <%
>               response.setContentType("application/vnd.ms-excel");
>               
>               HSSFWorkbook wb = new HSSFWorkbook();
>               HSSFSheet sheet_New = wb.createSheet("New Contacts");
> 
>               HSSFSheet sheet_Mod = wb.createSheet("Modified
> Contacts");
>               HSSFSheet sheet_Del = wb.createSheet("Deeleted
> Contacts");
>       
>               
>               HSSFRow header_New = sheet_New.createRow((short)0);
>               HSSFRow header_Mod = sheet_Mod.createRow((short)0);
>               HSSFRow header_Del = sheet_Del.createRow((short)0);
> 
>       
>               HSSFCell cell1_New = header_New.createCell((short)0);
>               HSSFCell cell2_New = header_New.createCell((short)1);
>               HSSFCell cell3_New = header_New.createCell((short)2);
>               HSSFCell cell4_New = header_New.createCell((short)3);
>               
>               cell1_New.setCellValue("First_Name");           
>               cell2_New.setCellValue("Last_Name");            
>               cell3_New.setCellValue("Middle_Name");          
>               cell4_New.setCellValue("Suffix_Name");          
>               
>               
>               HSSFCell cell1_Mod = header_Mod.createCell((short)0);
>               HSSFCell cell2_Mod = header_Mod.createCell((short)1);
>               HSSFCell cell3_Mod = header_Mod.createCell((short)2);
>               HSSFCell cell4_Mod = header_Mod.createCell((short)3);
>               
>               cell1_Mod.setCellValue("Suffix");               
>               cell2_Mod.setCellValue("Last_Name");            
>               cell3_Mod.setCellValue("Middle_Name");          
>               cell4_Mod.setCellValue("Suffix_Name");          
>               
>               
>               HSSFCell cell1_Del = header_Del.createCell((short)0);
>               HSSFCell cell2_Del = header_Del.createCell((short)1);
>               HSSFCell cell3_Del = header_Del.createCell((short)2);
>               HSSFCell cell4_Del = header_Del.createCell((short)3);
>               
>               cell1_Del.setCellValue("Deal_Name");            
>               cell2_Del.setCellValue("PAM_Name");             
>               cell3_Del.setCellValue("Middle_Name");          
>               cell4_Del.setCellValue("Suffix_Name");  
>                                   
>               wb.write(response.getOutputStream());
>               
> 
> %>
>  
> Let me know if you have any other suggestions.
> 
> thanks,
> -Aparna.
> 
> 
> 
> -----Original Message-----
> From: Sharma, Siddharth [mailto:[EMAIL PROTECTED]
> Sent: Monday, February 14, 2005 4:03 PM
> To: POI Users List
> Subject: RE: Opening HSSF Workbook in Excel
> 
> 
> response.setContentType("application/vnd.ms-excel");
> hssfWorkbook.write(response.getOutputStream);
> 
> where 
> response is an instance of HTTPServletResponse
> hssfWorkbook is the workbook you just created. An instance of
> HSSFWorkbook
> 
> 
> 
> -----Original Message-----
> From: Vytla, Aparna (GE Commercial Finance, NonGE)
> [mailto:[EMAIL PROTECTED] 
> Sent: Monday, February 14, 2005 3:59 PM
> To: [email protected]
> Subject: Opening HSSF Workbook in Excel
> 
> Hi Folks,
>   I'd like to know if we can open a HSSF workbook in Excel without
> creating a physical file on the filesystem.I tried writing 
> the workbook
> directly to the OutputStream of my JSP.But it doesn't work.
> 
> Post me if you have turn around to this.
> 
> Appreciate your response.
> 
> regards,
> -Aparna.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> 
> 
> --------------------------------------------------------------
> ----------
> For more information about Barclays Capital, please
> visit our web site at http://www.barcap.com.
> 
> 
> Internet communications are not secure and therefore the Barclays 
> Group does not accept legal responsibility for the contents of this 
> message.  Although the Barclays Group operates anti-virus programmes, 
> it does not accept responsibility for any damage whatsoever that is 
> caused by viruses being passed.  Any views or opinions presented are 
> solely those of the author and do not necessarily represent 
> those of the 
> Barclays Group.  Replies to this email may be monitored by 
> the Barclays 
> Group for operational or business reasons.
> 
> --------------------------------------------------------------
> ----------
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> Mailing List:     http://jakarta.apache.org/site/mail2.html#poi
> The Apache Jakarta Poi Project:  http://jakarta.apache.org/poi/
> 


-----------------------------------------------------------------
ATTENTION:
The information in this electronic mail message is private and
confidential, and only intended for the addressee. Should you
receive this message by mistake, you are hereby notified that
any disclosure, reproduction, distribution or use of this
message is strictly prohibited. Please inform the sender by
reply transmission and delete the message without copying or
opening it.

Messages and attachments are scanned for all viruses known.
If this message contains password-protected attachments, the
files have NOT been scanned for viruses by the ING mail domain.
Always scan attachments before opening them.
-----------------------------------------------------------------

Reply via email to