• 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

Export image in a word document using a jsp

 
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The jsp has the following code to open the jsp as a word document:

<%@ page contentType="application/msword" %>
<% response.addHeader("Content-Disposition", "attachment; filename=\"Cover_Letter.doc\";"); %>


Am using the following line of code to display the image in the word document :
<p>
<img src="file:///C:/modeln5.1/genzyme1.0/src/com/genzyme/ac/medicaid/report/GenzymeLogo.gif" alt=" GENZYME"
width="200" height="100">
</p>
even after changing the path (real/relative)the image does not get displayed in the word document(its a "X" getting displayed),
but the same path displays image if I remove the content type and the JSP page works normally.

Thanks,
Nishtha

[ March 19, 2007: Message edited by: nishtha verma ]
[ March 19, 2007: Message edited by: nishtha verma ]
 
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

Originally posted by nishtha verma:
This is an urgent requirement.



Please read this.
 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Are you trying to create a word document with JSP?
If so, this doesn't work.

You will need to look into 3rd party libraries for accessing and manipulating Microsoft Office documents from Java.
Jakarta POI is one such library.
 
nishtha verma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
The word document can be created from the JSP by just setting the contentType as mentioned in the lines above.

The issue is the image is not getting displayed in the word document and am not clear as to howto use the POI (Apache - 3rd Party API) to have the image displayed instead of the "X" (cross) - which in html/jsp implies that the wrong path is mentioned.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Originally posted by nishtha verma:
The word document can be created from the JSP by just setting the contentType as mentioned in the lines above.



No, it can not.
What you're doing is creating a text/html file and instructing the browser to open it with Word. This is why your images are not showing up. A true word document is a binary file containing the text, its markup, and any embedded images, all in one file. There is nothing in JSP for creating Microsoft proprietary format documents.
For that, you will need a third party product.

That being said, it sounds like Word is trying to interpret your HTML.
Have you tried putting an absolute URL in the image tag?
[ March 19, 2007: Message edited by: Ben Souther ]
 
nishtha verma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi Ben,

Thanks for the reply. The absolute URL does not work too.
What I was wondering is incase the word document does not recognise the html tag it will not even display a "X" with the alternate message being displayed....where the img src tag is used.

It would be great if you know the usage of POI (third party API) in this case and have some sample source code for the class and the method which export the image in the word document using a jsp.
 
Bear Bibeault
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
Use of POI is not a JSP topic. This topic has been moved to a more appropriate forum.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic