We did something like this too. We have a html/fax generation code that
turns our XML data and XSL into rtf. We then set the contentType =
"application" before sending the file back. This allows the pop-up dialog to
appear (to save the file). Also, if you set the contentType to "text/rtf" it
will be displayed directly in MSIE (and I think it requires a plugin..or
loads MS-WORD if your using Netscape).
The question I have is..when sending a file back to be "saved" by the user,
how can you set the filename that appears in the pop-up dialog?
> -----Original Message-----
> From: Ortiz, William J [mailto:[EMAIL PROTECTED]]
> Sent: Tuesday, November 14, 2000 8:05 AM
> To: [EMAIL PROTECTED]
> Subject: Re: Streaming RTF via JSPs
>
>
> It can be done with Servlets. Here's what I did for my
> current project, it
> is a web based app using servlets and JSP's:
>
> 1. We store the RTF files in the server, obviously in a directory the
> application can read. The files include some 'place-holders' that we
> replace later with mainframe data.
> 2. After we open the files to change the placeholders for
> real data, we
> stream them down to the user. The browser then opens up a
> Word window with
> the completed RTF file.
>
> I don't know if it can be done purely from JSP's. Since JSP's
> were designed
> for HTML and browser output in mind it might not be a good
> idea. RTF files
> have a very specific format that can get screwed very easily
> if you don't
> know what you're doing. But, since a JSP is essentially a
> servlet, there
> might be a way to do so.
>
> Here is some sample code. Some of it I took from "Java
> Servlet Programming"
> by Jason Hunter (ie. returnFile(...)). The class
> FileUtilities is a class we
> created that makes a copy of a file and stores it elsewhere
> with a name you
> provide, among other things. I had to ommit some code for
> security reasons,
> but I think you can grasp the idea. You could also look up
> page 92 (Serving
> Files) of the book I mentioned for the full example.
>
> public class PrintServlet extends HttpServlet{
> public void doPost(...............) yada yada yada{
> ....
> }
> ....
> ....
> private void createLetterDocument(HttpServletRequest req,
> HttpServletResponse res) throws IOException, ServletException{
> FileUtilities copier = new FileUtilities();
> String filename = "";
> ServletOutputStream out = res.getOutputStream();
> // Is this a CPC Customer? If not, do the following:
> if (!cpcCustomer){
> if ((Purchase.equals("true")) && Return.equals("true")){
> filename = session.getId() + "prletter.rtf";
> copier.copyFile("prletter.rtf", filename);
> }
> else{
> ...
> ...
> }
> String contentType =
> getServletContext().getMimeType(filename);
> res.setContentType(contentType);
> // add section to replace the placeholders
> fillDocument();// ?
> // add section to return file
> try{
> returnFile(filename, out);
> }catch(FileNotFoundException fnfe){
> }
> }
>
> public static void returnFile(String filename, OutputStream
> out) throws
> IOException, FileNotFoundException{
> FileInputStream fis = null;
> try{
> fis = new FileInputStream(filename);
> byte[] buf = new byte[4 * 1024]; // 4k buffer
> int bytesRead;
> while((bytesRead = fis.read(buf)) != -1){
> out.write(buf, 0, bytesRead);
> }
> }
> finally{
> if(fis != null)
> fis.close();
> }
> }
>
> William J Ortiz
> EDS E.Solutions/BlueSphere
> XEEP Buyout
> Phone: (716) 427-6892
> e-mail: [EMAIL PROTECTED]
> <mailto:[EMAIL PROTECTED]>
> e
>
>
> -----Original Message-----
> From: Whitwell, Carl [mailto:[EMAIL PROTECTED]]
> Sent: Monday, November 13, 2000 12:11 PM
> To: [EMAIL PROTECTED]
> Subject: Streaming RTF via JSPs
>
>
> Hi all
>
> I'm working on a document generation application that will
> generate RTF
> documents on the fly for viewing in the Web browser.
>
> I have an RTF file that I created in MS-Word. As a test, I
> have changed its
> extension to .jsp and placed it where it is visible to my jsp
> engine (IBM
> WebSphere 3). When I try to load the file using its url, the
> server takes
> ages (ok as I know it is "compiling" the jsp into a servlet)
> then bombs with
> the error I've included at the bottom. I've tried adding some jsp
> directives, such as content-type and buffer="none", but the
> error is the
> same. I've also removed all the graphics that were
> originally present,
> again to no avail.
>
> Does anyone have experience with RTF and JSP? Can it be
> done? If not, my
> project is in trouble!
>
> Cheers
>
> Carl.
>
> Here's the exception:
>
> java.io.UTFDataFormatException
> at java.lang.Throwable.(Compiled Code)
> at java.lang.Exception.(Compiled Code)
> at java.io.IOException.(Compiled Code)
> at java.io.UTFDataFormatException.(Compiled Code)
> at java.io.DataOutputStream.writeUTF(Compiled Code)
> at java.io.ObjectOutputStream.writeUTF(Compiled Code)
> at java.io.ObjectOutputStream.writeObject(Compiled Code)
> at java.io.ObjectOutputStream.outputArray(Compiled Code)
> at java.io.ObjectOutputStream.writeObject(Compiled Code)
> at
> com.sun.jsp.compiler.Jsp1_0ParseEventListener.endPageProcessin
> g(Compiled
> Code)
> at com.sun.jsp.compiler.Main.compile(Compiled Code)
> at com.sun.jsp.runtime.JspLoader.compile(Compiled Code)
> at com.sun.jsp.runtime.JspLoader.loadJSP(Compiled Code)
> at
> com.sun.jsp.runtime.JspServlet$JspServletWrapper.loadIfNecessa
> ry(Compiled
> Code)
> at
> com.sun.jsp.runtime.JspServlet$JspServletWrapper.service(Compiled
> Code)
> at
> com.sun.jsp.runtime.JspServlet.serviceJspFile(Compiled Code)
> at com.sun.jsp.runtime.JspServlet.service(Compiled Code)
> at javax.servlet.http.HttpServlet.service(Compiled Code)
> at
> com.ibm.servlet.engine.webapp.StrictServletInstance.doService(
> Compiled Code)
> at
> com.ibm.servlet.engine.webapp.StrictLifecycleServlet._service(
> Compiled Code)
> at
> com.ibm.servlet.engine.webapp.IdleServletState.service(Compiled
> Code)
> at
> com.ibm.servlet.engine.webapp.StrictLifecycleServlet.service(C
> ompiled Code)
> at
> com.ibm.servlet.engine.webapp.ServletInstance.service(Compiled
> Code)
> at
> com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispa
> tch(Compiled
> Code)
> at
> com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatc
> h(Compiled
> Code)
> at
> com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWe
> bAppDispatch(C
> ompiled Code)
> at
> com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.dispatch
> (Compiled
> Code)
> at
> com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.forward(
> Compiled Code)
> at
> com.ibm.servlet.engine.srt.WebAppInvoker.handleInvocationHook(
> Compiled Code)
> at
> com.ibm.servlet.engine.invocation.CachedInvocation.handleInvoc
> ation(Compiled
> Code)
> at
> com.ibm.servlet.engine.invocation.CacheableInvocationContext.i
> nvoke(Compiled
> Code)
> at
> com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByU
> RI(Compiled
> Code)
> at
> com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.servi
> ce(Compiled
> Code)
> at
> com.ibm.servlet.engine.oselistener.SQEventListenerImp$ServiceR
> unnable.run(Co
> mpiled Code)
> at
> com.ibm.servlet.engine.oselistener.SQEventListenerImp.notifySQ
> Event(Compiled
> Code)
> at
> com.ibm.servlet.engine.oselistener.serverqueue.SQEventSource.n
> otifyEvent(Com
> piled Code)
> at
> com.ibm.servlet.engine.oselistener.serverqueue.SQWrapperEventS
> ource$SelectRu
> nnable.notifyService(Compiled Code)
> at
> com.ibm.servlet.engine.oselistener.serverqueue.SQWrapperEventS
> ource$SelectRu
> nnable.run(Compiled Code)
> at
> com.ibm.servlet.engine.oselistener.outofproc.OutOfProcThread$C
> tlRunnable.run
> (Compiled Code)
> at java.lang.Thread.run(Compiled Code)
>
>
>
> This message is for the named person's use only. It may contain
> confidential, proprietary or legally privileged information. No
> confidentiality or privilege is waived or lost by any mistransmission.
> If you receive this message in error, please immediately
> delete it and all
> copies of it from your system, destroy any hard copies of it
> and notify the
> sender. You must not, directly or indirectly, use, disclose,
> distribute,
> print, or copy any part of this message if you are not the intended
> recipient. CREDIT SUISSE GROUP and each of its subsidiaries
> each reserve
> the right to monitor all e-mail communications through its
> networks. Any
> views expressed in this message are those of the individual
> sender, except
> where the message states otherwise and the sender is
> authorised to state
> them to be the views of any such entity.
> Unless otherwise stated, any pricing information given in
> this message is
> indicative only, is subject to change and does not constitute
> an offer to
> deal at any price quoted.
> Any reference to the terms of executed transactions should be
> treated as
> preliminary only and subject to our formal written confirmation.
>
> ==============================================================
> =============
> To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
> JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
> ==============================================================
> =============
> To unsubscribe: mailto [EMAIL PROTECTED] with body:
> "signoff JSP-INTEREST".
> Some relevant FAQs on JSP/Servlets can be found at:
>
> http://java.sun.com/products/jsp/faq.html
> http://www.esperanto.org.nz/jsp/jspfaq.html
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
> http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets
>
===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
Some relevant FAQs on JSP/Servlets can be found at:
http://java.sun.com/products/jsp/faq.html
http://www.esperanto.org.nz/jsp/jspfaq.html
http://www.jguru.com/jguru/faq/faqpage.jsp?name=JSP
http://www.jguru.com/jguru/faq/faqpage.jsp?name=Servlets