>I am able to send the attachment to the browser, and then save the
>attachment, however the browser's cursor remains in the
>hourglass mode indicating that it perceives that the request has not been
...

I have this problem as well, and have spent many hours searching the
microsoft sites, newsgroups, etc trying to find some reasonable answer as to
why the  waitcursor persists after the download completes - it's an Internet
Explorer problem only! I have a case open with Microsoft at the moment, and
still wating to hear back. The tech support guy I talked to said he coded a
similar scenario with CGI and a C program and did not experience the
waitcursor problem. (Never mind I sent the source for a stand-alone servlet
that demonstrates the bug)

The other problem you are having is due to attempting to open both
getWriter() and getOutputStream() I believe it's one or the other, but not
both.

If I come up with a solution to the waitcursor thing, I'll post it to the
list.

-Greg Purpura


-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Cor Ruiten
Sent: Tuesday, February 29, 2000 8:30 PM
To: [EMAIL PROTECTED]
Subject: Problem downloading binaries (JSP to Servlet to Browser)


I have checked the archives and have been unable to find a resolution to my
problem.

I am interested in sending a binary data stream (attachment) to the browser
so that the end-user can save these attachments
on their local workstation.

I am able to send the attachment to the browser, and then save the
attachment, however the browser's cursor remains in the
hourglass mode indicating that it perceives that the request has not been
completed yet. Additionally I obtain the following
exception:

Mon Feb 28 17:24:59 PST 2000: Running servlet
{ (Running servlet) java.lang.IllegalStateException: Already called
getOutputStream()
        at
com.livesoftware.jrun.JRunServletResponse.getWriter(JRunServletResponse.java
:150)
        at com.livesoftware.jsp.JRunJspWriter.flush(JRunJspWriter.java:188)
        at jsp.Pipeline.HelloCor._jspService(HelloCor.java, Compiled Code)
        at
com.livesoftware.jsp.HttpJSPServlet.service(HttpJSPServlet.java:31)
        at com.livesoftware.jsp.JSPServlet.service(JSPServlet.java:118)
        at javax.servlet.http.HttpServlet.service(HttpServlet.java:840)
        at com.livesoftware.jrun.JRun.runServlet(JRun.java, Compiled Code)
        at
com.livesoftware.jrun.JRunGeneric.handleConnection(JRunGeneric.java:116)
        at
com.livesoftware.jrun.service.web.JRunWebServiceHandler.handleOutput(JRunWeb
ServiceHandler.java:266)
        at
com.livesoftware.jrun.service.web.JRunWebServiceHandler.handleRequest(JRunWe
bServiceHandler.java, Compiled Code)
        at
com.livesoftware.jrun.service.ThreadConfigHandler.run(ThreadConfigHandler.ja
va, Compiled Code)
 }

The only place where I do a getOutputStream() is in my servlet, I suppose
that this means that somewhere in the JSP
processing it calls getOutputStream() as well. If this is the case then how
can Jason Hunter's returnFile utility work???

My inital rendered JSP page contains links of attachments that the user can
download. If the user clicks on one of these
links, then the user is goes to another JSP page that performs a re-direct
to a servlet that performs the actual
sending of binary data of the attachment to the user's browser.

Here are some code snippets:
        Snippet 1: Second JSP page to retrieve object and forward to servlet
        ====================================================================
        // url var
        String mimeId = request.getParameter("mimeId");
        byte[] mimeIdByteArray = ConversionUtil.toByteArray(mimeId);

        MimeDataHome home = client.getDataService().getMimeDataHome();
        MimeDataKey key = new MimeDataKey(mimeIdByteArray);
        MimeData oMime =
home.findByPrimaryKey(key,com.persistence.container.FindSource.k_cacheThenDa
tabase);

        // Testing purposes only, put object in the servlet's context for
now...
        getServletContext().setAttribute(mimeId, oMime);

        String nextPageId = "/servlet/FileDownload?mimeId=" + mimeId;
        response.sendRedirect(nextPageId);

        Snippet 2: Servlet performing the actual transmission of the binary
data

========================================================================
        public class FileDownload extends HttpServlet {

          public void doGet(HttpServletRequest req, HttpServletResponse res)
throws
java.rmi.RemoteException, IOException {

                // First we need the ServletContext and the OutputStream...
                ServletContext thisCtx =
getServletConfig().getServletContext();
        ServletOutputStream outStream = res.getOutputStream();

                // Then retrieve the mimeId from the request and then pull
the
SinglePartMimeData object
                // from the ServletContext...
                String mimeId = req.getParameter("mimeId");
                SinglepartMimeData oMime =
(SinglepartMimeData)thisCtx.getAttribute(mimeId);

                // Clean up after ourselves...
                thisCtx.removeAttribute(mimeId);

                // Set the ContentType...
                if (!oMime.getPrimaryTypeNull() && !oMime.getSubTypeNull() )
                        res.setContentType(oMime.getPrimaryType() + "/" +
oMime.getSubType() );
                else
                        res.setContentType("application/octet-stream");

                // Set the header value for Content-disposition...
                res.setHeader("Content-disposition", "attachment; filename="
+
oMime.getFilename() );  // Download under IE, downloads under NS
                res.setContentLength(oMime.getContent().length);

                // Finally dump the content of the mime object to the output
stream...
                outStream.write(oMime.getContent() );

                outStream.flush();
                outStream.close();
          }

}

I appreciate any input and I thank you for your time,

Cor Ruiten

===========================================================================
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