On Sun, 10 Feb 2002, Mike Duffy wrote: > The tech tip belows show how to dynamically create an image within a > servlet and send it to the output stream. > > http://developer.java.sun.com/developer/JDCTechTips/2001/tt0821_update.html > > In most cases developers want to send both HTML text and images when > dynamically creating a web page. How can this be done?
As separate requests, one for the HTML and one for each image. Think about it, that's the way web servers handle static HTML pages with images, there's no reason dynamic pages need be any different. Per HTTP, each response can only be of one type, not mixed, so if you have more than one type, you need to have more than one response. > "The Servlet specification requires that servlets not call both > ServletResponse.getOutputStream() and ServletResponse.getWriter(). " > > So, the only way I can think of doing this (images and HTML) is to > transform the HTML text into a byte array and use the method > write(byte[] b) from the class OutputStream. > > Can anyone think of a more elegant way to do this? Per the above, use multiple separate requests/responses, one for the HTML and one for each image. > Also, "Because JSP pages already call getWriter(), they must not > also call getOutputStream()." I think this means that it is > impossible to dynamically create images from a JSP (which was the > point of the tech tip above). > > Can anyone think of a way to dynamically generate images within a > JSP? I think you may be overanalyzing this problem. Remember, JSPs are really just servlets, but viewed differently, so as to make them more intuitive/easier to create/maintain/understand -- that is, they allowing looking at a servlet as an HTML page with some code interspersed. But an image is not an HTML page at all, so there is no reason/benefit to view it as a JSP. I think if you think of having separate requests that handle just creating images, everything else will fall into place. Milt Epstein Research Programmer Software/Systems Development Group Computing and Communications Services Office (CCSO) University of Illinois at Urbana-Champaign (UIUC) [EMAIL PROTECTED] ___________________________________________________________________________ To unsubscribe, send email to [EMAIL PROTECTED] and include in the body of the message "signoff SERVLET-INTEREST". Archives: http://archives.java.sun.com/archives/servlet-interest.html Resources: http://java.sun.com/products/servlet/external-resources.html LISTSERV Help: http://www.lsoft.com/manuals/user/user.html
