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

Export image in a word document using a jsp  RSS feed

 
nishtha verma
Greenhorn
Posts: 6
  • Mark post as helpful
  • send pies
  • 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 ]
 
Bear Bibeault
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by nishtha verma:
This is an urgent requirement.


Please read this.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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 Redhat VI Editor
  • Mark post as helpful
  • send pies
  • 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
  • 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
Author and ninkuma
Marshal
Posts: 65828
134
IntelliJ IDE Java jQuery Mac Mac OS X
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Use of POI is not a JSP topic. This topic has been moved to a more appropriate forum.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!