• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

response.setContentType ("application/vnd.ms-excel")

 
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
By doing response.setContentType("application/vnd.ms-excel"), we allow a JSP output to be viewed and downloaded as an excel. But the point is the file on the server is still that JSP page, difference is browser can download it as excel. Is there a way that we can directly "create" or "convert" that JSP into an excel file on the server ? For example, that JSP includes only two parts --

<% response.setContentType("..."); %> <!-- part 1 -->
HTML part <!-- part 2 -->

Can we "translate" the "Part I" into some understandable things and put together with "Part II", then save it as a ".xls" file ?
 
author & internet detective
Posts: 41860
908
Eclipse IDE VI Editor Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Artemesia,
You can build an Excel file at runtime containing anything you want. For simple files, you can just output a comma delimited file. For more comples ones, look into Apache's HSSF/POI.
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeanne Boyarsky:
Artemesia,
You can build an Excel file at runtime containing anything you want. For simple files, you can just output a comma delimited file. For more comples ones, look into Apache's HSSF/POI.




thanks. But, I still want to know if the approach I mentioned is feasible.
 
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Jeanne's answer actually meant "Yes"

With POI (look up the meaning of the acronym, it's worth it)
you have a (somewhat limited) access to the Object Model of
EXCEL.
You construct the Objects and stream them out to a fil, which
obviously happens on the serverside.
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Kindly remember that the whole purpose of JSP is to make HTML pages. Trying to make a JSP serve any content that needs to be in an exact text or binary format is inappropriate use of the technology. Use a servlet instead, the servlet API is not that hard.
Bill
 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by Jeffrey Spaulding:
Jeanne's answer actually meant "Yes"

With POI (look up the meaning of the acronym, it's worth it)
you have a (somewhat limited) access to the Object Model of
EXCEL.
You construct the Objects and stream them out to a fil, which
obviously happens on the serverside.



pardon me if I still don't get it. I think that, if I use my original methodology, on the server, I still only get that JSP page with a different content type. I don't really have an excel .xls generated.
Am I right ?

Although I know nothing about POI, it looks like a different way to do things and it generates files directly I guess.
 
Sheriff
Posts: 67746
173
Mac Mac OS X IntelliJ IDE jQuery TypeScript Java iOS
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
You don't send any "file" to the browser. You send a stream of data. The content type tells the browser how to interpret the stream. It's your responsiblity to make sure that the format of the stream corresponds to what you told the browser you were sending it.

If you send a PDF-formatted stream to the browser and tell the browser that the content type is a Word document, obviously no automatic conversion will take place.

That's where tools like POI come in, and why it's a spectacularly bad idea to do something like this in a JSP.
[ September 07, 2005: Message edited by: Bear Bibeault ]
 
Seriously? That's what you're going with? I prefer this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic