How are you outputting Word formatting data in a JSP? Are you using a library like POI? If so, it is advised to put such Java code in a servlet and not in the JSP.
Or are you trying to open an HTML document in Word? This is likely to cause you problems. Office 2007 gives a security warning if the file extension does not match the content. Which means HTML in a .doc file will gives this warning.
That is, is there a semi-standard for dealing with this issue or position in the jsp file where you should put switches over content type?
This is actually easier to answer because it's general. If I am understanding what you are tyring to do, you have three different output formats in the same JSP. It would be better to have different JSPs (or servlets for the Word/Excel ones) for each format.
My question is what takes priorty, the response.setContentType or the <head> <meta http-equiv="Content-type" content="text/html" ...
the answer must be the response.setContentType but the answer isn't obvious to me
I was playing around with the example you quoted and see that only "response.setContentType" actually does the required thing(like opening MS-WORD for application/msword). There is no effect of setting <meta http-equiv="Content-type" content="application/msword" ...
What could be the reson for this? Are doing these two things any different from each other? [ October 15, 2008: Message edited by: Satya Maheshwari ]
Thanks and Regards
Joined: Oct 03, 2008
Thanks for the responses.
My intention is NOT to do this in a servlet because I figure I'm just outputting HTML. First, thank you, I'll check out the Apache POI. Maybe that is the approach I want and I'll test against Internet 7.0.
But what I like was the fact that I could have this HMTL file, with a table in it. Then if users wanted to "print" this to the printer, the quick and dirty way I would use is to convert it to word via the "setContentType".
Jeanne Boyarsky, also suggested the use of a servlet to print out stuff in three different formats (html, doc, and excel). I don't know what a word format would be. Would I still use html tags?
Craig, The user couldn't just print it in the browser?
In Office 2003, you could get away with calling an HTML file a Word document and having it open in Word. In Office 2007, you get the security prompt so this is discouraged. POI will give you the binary Word format so it is a real word document.
If you just have HTML, putting in a JSP is fine. I think you'll have "real Java code" once you get into Excel and Word at which time you can use a servlet for the two formats.