logo       

How to display (browser) images (inputstream) from the server?: msg#00204

java.dwr.user

Subject: How to display (browser) images (inputstream) from the server?

Hi!
Thanks for your reply...
But this is very annoying.
I mean... of all examples I have read on the web they all say that you have to write to the outputstream of the httpservletresponse object.
But when doing so i'm getting the irritating illegalargumentexception...
Does dwr set the response to "read only"?!
But if using dwr and getting the correct inputstream in my javamethod, what object type could I return to the _javascript_ (File/OutputStream) for making it work?!
And how should I write my _javascript_... is it correct to use a div-tag?!
/Daniel.
Content-Type: multipart/signed; micalg=sha1; boundary=Apple-Mail-9-932872763; protocol="application/pkcs7-signature"
From: Marius Seritan <marius-ALVOsWIOdiJWk0Htik3J/w@xxxxxxxxxxxxxxxx>
Date: Mon, 26 Feb 2007 10:13:20 -0800
Subject: [dwr-user] How to display (browser) images (inputstream) from the server?

Typically you would read URLs through DWR and use _javascript_ to  
generate img nodes to display the URLs. Basically the download of the  
binary data is done by the browser. If you do want to return through  
DWR the binary data that makes up the images you can add it as  
members in your class/objects. I do not know how/if DWR will  
serialize the data and how you will process it on the _javascript_ side.

-- 
Marius Seritan
marius-ALVOsWIOdiJWk0Htik3J/w@xxxxxxxxxxxxxxxx



On Feb 26, 2007, at 9:57 AM, Rickardsson Daniel wrote:

> Hi!
>
> How can I display images that is being read from a server?!
>
> I want to read many images and therfore using dwr.
>
> In my ajax-java-method I use:
> WebContext ctx = WebContextFactory.get();
> HttpServletRequest request = ctx.getHttpServletRequest();
> HttpServletResponse response = ctx.getHttpServletResponse();
>
> //then gets the outputstream
> ServletOutputStream out = response.getOutputStream();
>
> //writes my picture (inputstream) to my outputstream
> StreamUtils.copyStream(is, out);
>
> And on client side I have the following:
> document.getElementById('map').style.backgroundImage =  
> MapClass.getMap(<parameters>);
>
> No picture is shown and my log says:
> 2007-02-26 18:02:57,528 ERROR [http-8080-1]  
> org.apache.catalina.core.StandardWrapperValve.invoke()  
> Servlet.service() for servlet myApplication threw exception
> java.lang.IllegalStateException: getOutputStream() has already been  
> called for this response
>  at org.apache.catalina.connector.Response.getWriter(Response.java: 
> 599)
>  at org.apache.catalina.connector.ResponseFacade.getWriter 
> (ResponseFacade.java:195)
>  at uk.ltd.getahead.dwr.impl.DefaultExecProcessor.handle 
> (DefaultExecProcessor.java:157)
>  at uk.ltd.getahead.dwr.impl.DefaultProcessor.handle 
> (DefaultProcessor.java:81)
>  at uk.ltd.getahead.dwr.AbstractDWRServlet.doPost 
> (AbstractDWRServlet.java:162)
>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>  at  
> org.springframework.web.servlet.mvc.ServletWrappingController.handleRe 
> questInternal(ServletWrappingController.java:174)
>  at  
> org.springframework.web.servlet.mvc.AbstractController.handleRequest 
> (AbstractController.java:153)
>  at  
> org.springframework.web.servlet.mvc.SimpleControllerHandlerAdapter.han 
> dle(SimpleControllerHandlerAdapter.java:45)
>  at org.springframework.web.servlet.DispatcherServlet.doDispatch 
> (DispatcherServlet.java:806)
>  at org.springframework.web.servlet.DispatcherServlet.doService 
> (DispatcherServlet.java:736)
>  at org.springframework.web.servlet.FrameworkServlet.processRequest 
> (FrameworkServlet.java:396)
>  at org.springframework.web.servlet.FrameworkServlet.doPost 
> (FrameworkServlet.java:360)
>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
>  at javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
>  at org.apache.catalina.core.ApplicationFilterChain.internalDoFilter 
> (ApplicationFilterChain.java:252)
>  at org.apache.catalina.core.ApplicationFilterChain.doFilter 
> (ApplicationFilterChain.java:173)
>  at org.apache.catalina.core.StandardWrapperValve.invoke 
> (StandardWrapperValve.java:213)
>  at org.apache.catalina.core.StandardContextValve.invoke 
> (StandardContextValve.java:178)
>  at org.apache.catalina.core.StandardHostValve.invoke 
> (StandardHostValve.java:126)
>  at org.apache.catalina.valves.ErrorReportValve.invoke 
> (ErrorReportValve.java:105)
>  at org.apache.catalina.core.StandardEngineValve.invoke 
> (StandardEngineValve.java:107)
>  at org.apache.catalina.connector.CoyoteAdapter.service 
> (CoyoteAdapter.java:148)
>  at org.apache.coyote.http11.Http11AprProcessor.process 
> (Http11AprProcessor.java:833)
>  at org.apache.coyote.http11.Http11AprProtocol 
> $Http11ConnectionHandler.process(Http11AprProtocol.java:639)
>  at org.apache.tomcat.util.net.AprEndpoint$Worker.run 
> (AprEndpoint.java:1285)
>  at java.lang.Thread.run(Unknown Source)
>
> Does anyone have any idea what to do?!
<Prev in Thread] Current Thread [Next in Thread>
Google Custom Search

News | FAQ | advertise