We found the same situation with IE, Netscape works fine with it.  It is a
documented bug, I think I found the info in the Apache web site.  Anyway, I
included it in our project documentation:

1) A documented bug in Internet Explorer prevents the browser from opening
binary data or files downloaded in a Word window unless the file has a .doc
or .rtf extension; even though the Content Type of the data is specified to
be "application/msword", Internet Explorer will not open the document.
Servlets commonly send data without an extension.  To solve this problem,
when submitting input from Print.html to the PrintServlet, a special
parameter must be sent in the request URL.  In this case, the request must
be made in the form: PrintServlet?.rtf (i.e.
http://serveraddress/servlet/PrintServlet?.rtf ), this way IE will be forced
to interpret the Content Type correctly.

If you are using a link or form to output the rtf file you could add the
'?.rtf' to your query string!! I hope this is what you were looing for.

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: Tuesday, November 14, 2000 11:28 AM
To: [EMAIL PROTECTED]
Subject: Re: Streaming RTF via JSPs


Thanks William

Yes we also have an application that performs exactly the same task.  I
wanted to use jsps, however, because of the ease of plugging in your own
content with jsp:getProperty.

I've just found out that it is in fact a bug in WebSphere 3.0.1 - we've
tried it in WebSphere 3.0.2 and 3.5 and it works fine.  So there you have it
- don't try and stream RTFs through WS3.0.1.

Only problem is getting the browser to recognise it as RTF without giving
the file an RTF extension.  This will manifest itself in the production
system, where we'll be using a central "Control" servlet (see the
Fields/Kolb book) so the user will never see the JSP file in their url.  I
think we'll have to name the servlet something.rtf in order to get the
browser to recognise it, unless anyone has a better idea...

-----Original Message-----
From: Ortiz, William J [mailto:[EMAIL PROTECTED]]
Sent: 14 November 2000 16:05
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.endPageProcessing(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.loadIfNecessary(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(Compiled Code)
        at com.ibm.servlet.engine.webapp.ServletInstance.service(Compiled
Code)
        at
com.ibm.servlet.engine.webapp.ValidServletReferenceState.dispatch(Compiled
Code)
        at
com.ibm.servlet.engine.webapp.ServletInstanceReference.dispatch(Compiled
Code)
        at
com.ibm.servlet.engine.webapp.WebAppRequestDispatcher.handleWebAppDispatch(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.handleInvocation(Compiled
Code)
        at
com.ibm.servlet.engine.invocation.CacheableInvocationContext.invoke(Compiled
Code)
        at
com.ibm.servlet.engine.srp.ServletRequestProcessor.dispatchByURI(Compiled
Code)
        at
com.ibm.servlet.engine.oselistener.OSEListenerDispatcher.service(Compiled
Code)
        at
com.ibm.servlet.engine.oselistener.SQEventListenerImp$ServiceRunnable.run(Co
mpiled Code)
        at
com.ibm.servlet.engine.oselistener.SQEventListenerImp.notifySQEvent(Compiled
Code)
        at
com.ibm.servlet.engine.oselistener.serverqueue.SQEventSource.notifyEvent(Com
piled Code)
        at
com.ibm.servlet.engine.oselistener.serverqueue.SQWrapperEventSource$SelectRu
nnable.notifyService(Compiled Code)
        at
com.ibm.servlet.engine.oselistener.serverqueue.SQWrapperEventSource$SelectRu
nnable.run(Compiled Code)
        at
com.ibm.servlet.engine.oselistener.outofproc.OutOfProcThread$CtlRunnable.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

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

Reply via email to