Win a copy of Murach's Python Programming this week in the Jython/Python forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic

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

 
Artemesia Lakener
Ranch Hand
Posts: 162
  • Mark post as helpful
  • send pies
  • 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 ?
 
Jeanne Boyarsky
author & internet detective
Sheriff
Posts: 36396
453
Eclipse IDE Java VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Jeffrey Spaulding
Ranch Hand
Posts: 149
  • Mark post as helpful
  • send pies
  • 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.
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13078
6
  • Mark post as helpful
  • send pies
  • 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
  • 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.
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65824
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • 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 ]
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!