Hi.
You can not do it with JSP cause You are unable to get OUtputStream.
You should Use servlet

Don't pay match attention on getting the connection.
Regards
Valik

code snippet :


        private void sendItemContent( Hashtable params )
                        throws PRMEdispatchTo,ServerException, ORMException
        {
                HttpServletRequest request      =
(HttpServletRequest)params.get("request");
                HttpServletResponse response    =
(HttpServletResponse)params.get("response");

                try
                {
                        BigInteger theId = WebUtil.getSingleParameterAsBigInteger( 
params, "Id");
                        String operation =
bUtil.getSingleParameterAsString(  params,"opReserved" );

                        if ( operation.equals("03001") ) // download
                        {

                                PrintWriter outp = response.getWriter();
                                outp.println("<html>");
                                outp.println("<script>");
                                outp.println("window.onunload = unloadhandler;");
                                outp.println("function unloadhandler()");
                                outp.println("{");
                                outp.println(" this.opener.refreshDoc();");
                                outp.println("}");
                                outp.println("</script>");
                                //outp.println("<body onblur='this.focus()'>");
                                outp.println("<body>");
                                outp.println("<a 
href='service?op=00000000000003002&Id="+theId+"'>Get
Item Version</a>");
                                outp.println("<br/>");
                                outp.println("If successful close this window.");
                                outp.println("</body>");
                                outp.println("</html>");
                                outp.close();
                                return;
                        }


                        String theBlobTableName = "NMSSingleFileStream";
                        String theBlobFieldName = "associatedBlob";


                        logWriter.log("ServiceForActor - request for BLOBContent by " +
theId,LogWriter.DEBUG);

                        ORMDBSession theDBSession = null;

                    boolean connectionFromTransaction = false;
                        if ( request.getSession(false).getAttribute("p" + theId) != 
null )
                        {
                                try
                                {
                                    theDBSession =
(ORMDBSession)request.getSession(false).getAttribute("p" + theId);
                                    if ( ! theDBSession.getConnection().isClosed() )
                                        connectionFromTransaction = true;
                                        else
                                                
request.getSession(false).removeAttribute("p" + theId);
                                }
                                catch (Exception exept )
                                {}
                        }
                        if ( !connectionFromTransaction )
                        {
                                //   DBSession
                                theDBSession = new ORMDBSession();
                                Connection theConnection = 
NMSConnectionManager.getConnection();
                                theDBSession.open(theConnection);
                        }

                        ServletOutputStream outS = response.getOutputStream();

                        InputStream theInputStream = null;

                        try
                        {
                                // Write BLOB data
                                theInputStream = ORMBlob.getBlobValue(
                                        theDBSession.getConnection(),
                                        theBlobTableName,
                                        theBlobFieldName,
                                        theId
                                );
                        }
                        catch ( Exception eee )
                        {
                                logWriter.log( eee,"",LogWriter.DEBUG);
                        }

                        if ( operation.equals("03002") ) // download
                        {
                                response.setContentType("application/x-msdownload");
                                response.setHeader("Accept-Ranges","bytes");

                                NMSSingleFileContent theSt = new NMSSingleFileContent( 
theId );
                                theSt.setDBSession( theDBSession );
                                response.setHeader("Content-Disposition", "attachment; 
filename=\"" +
theSt.getOriginalName() + "\"");
                                response.setHeader("Content-Length",
tring.valueOf( theInputStream.available() ) );
                        }
                        else if ( operation.equals("03000") )  // preview
                        {

                                //response.setHeader("Content-Length",
tring.valueOf( theInputStream.available() ) );
                                response.setContentType("image/jpeg");
                        }


                        try
                        {
                                int theData;
                                while ( (theData = theInputStream.read())!=-1 ) 
outS.write(theData);
                        }
                        catch (Exception e)
                        {
                                logWriter.log( e,"",LogWriter.DEBUG);
                        }

                        // Closing resources
                        outS.close();
                        if ( !connectionFromTransaction )
                        {
                                try { theDBSession.close(); }
                                catch (ORMException orme2)
                                {
                                        logWriter.log( orme2,"",LogWriter.DEBUG);
                                }
                        }
                        //
                }
                catch (IOException ioe)
                {
                        produceError( ioe,params );
                }
        }// of sendItemContent







-----Original Message-----
From: A mailing list about Java Server Pages specification and reference
[mailto:[EMAIL PROTECTED]]On Behalf Of Schot, P.J.N. van der
Sent: Wednesday, December 20, 2000 3:50 PM
To: [EMAIL PROTECTED]
Subject: Publishing images (Blob-format)from the DB with JSP


Hi all,

I want to publish image file(stored in db,type is blob) to internet using
jsp. Does any one have the method to view image in the browser using jsp
from BLOB field, without saving it first to a file.

Thanks,

Patrick

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff
JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST
DIGEST".
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


_________________________________________________________
Do You Yahoo!?
Get your free @yahoo.com address at http://mail.yahoo.com

===========================================================================
To unsubscribe: mailto [EMAIL PROTECTED] with body: "signoff JSP-INTEREST".
For digest: mailto [EMAIL PROTECTED] with body: "set JSP-INTEREST DIGEST".
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