Displaying a BufferedImage in a JSP

I want to build a JPG image as a BufferedImage using
JPEGImageDecoder.decodeAsBufferedImage() and then set this
BufferedImage object as an attribute of a user's Session (this is all done within a servlet). I then want a JSP to be able to display the image as part of the page, via the session object. I'm doing this because I want to create the images on the server but not write them to disk so that they will expire along with the user's Session and I don't have to do any clean up of the image files. Is there a way to do this ? I have tried something like the below with no success:
in the servlet:
HttpSession session = request.getSession(true);
session.setAttribute("testImage", regionOfInterestImage);
in the JSP:
<img src="<%= session.getAttribute("testImage") %>"
alt="IMAGE NOT FOUND">
If anyone has an idea as to how I can pull this off then please
respond ! I can't find much at all on this sort of thing in all the
references I have available.
Thanks in advance...
-James

I don't know how exactly to do this, but typically you would produce the image in a servlet, setting the mime type appropriately and then have a normal image link <img src="/servlet/url/servletname"> in your jsp page, to display it.

Similar Messages

  • Display pop ups in the jsp by using Java script

    Hi
    can any body say ,how to display pop ups in the jsp by using Java script ?

    that's correct. You can use the below code for AJAX request.
    <script type="text/javascript">
    var httpObject = getHTTPObject();
    //create XMLHttpRequest object
    function getHTTPObject() {     
         var xmlhttp;
         if (window.XMLHttpRequest) // if Mozilla, Safari etc
              xmlhttp = new XMLHttpRequest();
         else if (window.ActiveXObject){ // if IE
              try {
                   xmlhttp = new ActiveXObject("Msxml2.XMLHTTP");
              catch ( e ){
                   try{
                        xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
                   catch ( e ){}
         return xmlhttp;
    //define the function to send the request
    function sendRequest(){
        var currDesc = document.getElementById("description").value;
        var URL =  "manageMaintAction.do"; //action mapping in your struts-config
        var queryString = "currDesc="+escape(currDesc); //get the currDesc value in your action class like request.getParameter("currDesc")
        httpObject.open( "Post", URL, true );
        httpObject.onreadystatechange = cbFn;
        httpObject.setRequestHeader( "Content-Type", "application/x-www-form-urlencoded");
        httpObject.send(queryString);
    //callback fn
    function cbFn() {
        if (httpObject.readyState == 4)
             if (httpObject.status == 200)
              var result = httpObject.responseText;
              alert(result);
    </script>

  • Displaying data in xml using jsp

    how do we display data in database from jsp using xlst format in xml browser view

    how do we display data in database from jsp using xlst
    format in xml browser viewRefer this Post
    http://forum.java.sun.com/thread.jsp?forum=45&thread=482077&tstart=0&trange=15
    -Regards
    Manikantan

  • Display 'no photo' in a JSP when photo is not present in DB

    Hi All
    I have stored an image in database uploded from the JSP. The DB has a BLOB column for the image. I have to display a single record at a time. I am able to display the image at the JSP also using <img> tag and specifying the JSP name fetching the image as the src attribute of the <img> tag.
    My doubt is, if the image is not uploded for that record how to display some error message(like 'No Photo Uploaded') on the JSP page? and how can we also suppy a link to upload the photo, if already not uploaded. Since I am displaying the image as a part of another JSP having an <img> tag to display the image.
    Could someone please help me??
    Thanks & Regards
    Inder Jeet Singh

    Use an attribute to determine whether the record has a photo uploaded or not. Check the attribute value in the JSP and write the scriplet accordingly.
    Example:
    <% if (request.getAttribute("Photo") == null){
    %> <TR>
         <TD align="center" colspan="2">
              <CENTER><IMG src="Photo Source here" height="250" width="375" align="middle">
              </CENTER>
         </TD>
    </TR>
    <% }else{
    %>          
    <TR>
         <TD align="right"><FONT size="1">Building Photo:</FONT></TD>
         <TD><INPUT type="submit" name="" value="Associate Photo" onclick="return buildingPhoto()"></TD>
    </TR>
    <% } %>     
    In the above example I set the Photo attribute to null if there exists a photo.
    Message was edited by:
    srpunreddy

  • Displaying Crystal reports in a JSP Page

    hello,
    Can anybody help me out in displaying Crystal reports on a JSP page.
    which needs to be deployed on weblogic server and oracle database.
    i am new to crystal report and dont have much idea how to proceed.
    if you can give me a pointer how to start then i can proceed.
    waiting for the reply eagerly

    Start with the Crystal reports site.
    [url http://www.businessobjects.com/products/dev_zone/java/default.asp?ref=devzone_main] Java zone has some documentation and basic examples on how to do it

  • Displaying pdf file in a jsp page...

    hi,
    I want to display a pdf document in a jsp page. i got that pdf file from a servlet class(MVC Architecture) through session. now my problem is to display that pdf file in my jsp page. can anyone give me a idea to solve this problem..

    hi,
    i used that code in scriplets. Actually my problem is I got one pdf file from session and i stored that file in a File object. the code is ..
    File pdfDocument = (File) session.getAttribute(CommonConstants.EBILL_PDF_DOCUMENT);
    now i have to display this pdf file in jsp..

  • How to display a pdf file in jsp

    hi,
    How to display a pdf file in jsp iam having a class which will return fileinputstream of the file object. the pdf file is in server.
    regards
    Arul

    A JSP is a combo of HTML and Java, so you can't really "display" a PDF file in a JSP.
    You can provider a href link to the PDF file in your JSP.
    You can use some utility package to read the contents of the PDF, pull certain things out of it, and display that in your JSP as html
    In a servlet you can set the content type to application/pdf and write the binary data of the PDF back to the browser. Once the browser finishes reading in the data it should open the PDF.

  • Displaying a BufferedImage

    Hello,
    I'm building a program that needs to display a BufferedImage. I created a sub class of JPanel whom's only purpose is to display a BufferedImage, so instead of using drawImage, could I simply assign the Graphics2D object of my BufferedImage to the one of my component (see code below)?
    paintComponent(Graphics g){
        BufferedImage pic = getPic();
        g = pic.getGraphics();
    }

    Hello,
    I'm building a program that needs to display a
    BufferedImage. I created a sub class of JPanel whom's
    only purpose is to display a BufferedImage, so
    instead of using drawImage, could I simply assign the
    Graphics2D object of my BufferedImage to the one of
    my component (see code below)?
    paintComponent(Graphics g){
    BufferedImage pic = getPic();
    g = pic.getGraphics();
    Hi,
    No that doesn't work. You can't change what g originally references. You only got a copy of that reference in the method.
    What is your actual question?
    /Kaj

  • Displaying Korean Characters on my jsp

    I would like to display korean characters in my jsp....the characters that i want to display are read from an xml file using the sax parser... how will i do this?

    Case 1 - In a JSP only.
    In a JSP you need to set the following and it will display your respective charset. Substitute xxx for your required character set.
    <%response.setContentType="charset=xxx"%>.
    Case 2 - In an XML file and JSP
    If you have an XML file, be sure to define the encoding. Be sure to change the encoding to your Korean charset.
    <?xml version="1.0" encoding="ISO-8859-2"?>
    You will the need to write an XSL which you can apply to your XML file using Xalan and output the resulting HTML in a JSP. I assume your user-agent will be a web browser, although you can use WML, cHTML and VoXML or even another XML file.
    Rajesh Thiharie
    New Delhi, India
    91 124 6455511 x 109 Work

  • Issue with displaying images from bestseller.inc.jsp

    Hello all,
    I'm new in developing with NWDI and I'm having this small problem:
    in bestseller.inc.jsp (which includes productlist.jsp) there are two links with a product's code and a products description, which when clicked, navigate to productDetailsISA.jsp with the details of the product. While the images of all the products from other jsp's (for example from ProductsISA.jsp) display correctly in the ProductDetailsISA.jsp, there is a problem with the images of the products from bestseller and recommendations jsp's (they both include productlist jsp).
    The code for creating the links *in productlist.jsp is the following:
    <li> <a href="<isa:webappsURL name="b2b/productdetail.do"/><%=ShowProductDetailAction.createDetailRequest(product,displayScenario) %>">
                          <%=JspUtil.encodeHtml(product.getDescription()) %>
                        </a> </li>
    and the code for displaying products's images in ProductDetailsISA.jsp is this:
    <td width="7%" rowspan="2" headers="Product image">
                   <img src="<isa:imageAttribute guids="DOC_PC_CRM_IMAGE,DOC_P_CRM_IMAGE" name="webCatItem" defaultImg="mimes/shared/no_pic.gif"/>"   width="250"  height="250"/>
              </td>
    I have no idea how isa:imageAttribute tag works, so I was wandering if this problem is somehow connection with the inner workings of this tag.
    Could someone help please?
    Thank you very much in advance

    I think this is not the right forum to post your Question

  • How to display XML content in a JSP

    Hi,
    can anyone help me in displaying xml content in a JSP?

    I think you want to display value from XML page to the
    JSP.If thats the case you can try out this
    xml...
    <component-profile>
            <property name="parm" value="Hi"/>
    </component-profile>
    jsp...
    <% var=profile.getProperty("parm");%>
    Hope this helps
    gEorgE

  • Displaying a generated pdf in jsp

    I've generated a pdf using jasper report, which is present in the dir(d:/reports), i need to display this file in the jsp(reports.jsp),i cannot create the report in the jsp.....

    You can write a Servlet which would read the file contents using the standard input/output stream of java and render the response...
    For reference find the code snippet:
    String fileName=file.getName();
    response.setHeader("Content-Disposition","attachment; filename=\""+fileName+"\"");
    response.setContentLength((int)file.length());
    response.setContentType("application/zip");
    java.io.InputStream in = null;
    java.io.OutputStream out = null;
    try {
    in = new java.io.BufferedInputStream(new FileInputStream(file) );
    out = new java.io.BufferedOutputStream(response.getOutputStream() );
    pipe(in,out,2048);
    } finally {
    if( in != null ) try {
    in.close();
    } catch( IOException ioException ) { ioException.printStackTrace(); }
    in.close();
    out.flush();
    out.close();
    public  long pipe(java.io.InputStream in, java.io.OutputStream out,
                   int chunkSize) throws IOException {
              if( chunkSize < 1 ) {
                   throw new IOException("Invalid chunk size.");
              byte[] buf = new byte[chunkSize];
              long tot = 0;
              int n;
              while( (n=in.read(buf)) != -1 ) {
                   out.write(buf,0,n);
                   tot += n;
              return tot;
         }

  • Displaying a BufferedImage in a GUI

    I want to display a BufferedImage in my GUI.
    The BufferedImage is a screen snapshot created by the createScreenCapture() method in the Robot class. I know how to save it to file, but how would i display it in a GUI without saving it ??
    Would be really grateful for any help.
    Thanks
    Rob

    In the painting method of your GUI, you could cast the Graphics object into a Graphics2D. The Graphics2D has a method
    drawImage(BufferedImage img, BufferedImageOp op, int x, int y);

  • How to display List of objects in jsp?

    Hi,
    I have a list containing Collection of bean objects.
    Now I want to display the values in the list of objects in a jsp using JSTL.
    Any body help me how to retrieve the bean objects from the List and how can i display that values in the jsp.
    Advanced Thanks,
    Mahendra

    Have you tried to use <:forEach></c:forEach> tag available in jstl?

  • To display spanish characters on a JSP when the JSP is inside one portal

    Hi All,
    Previously, I had posted my query here that how to display spanish characters on a JSP screen.
    I got a solution that to add
    <%@ page contentType="text/html;charset=UTF-8" language="java" %>
    to the JSP and to save the JSP in 'UTF-8'encoding format.
    This works well in case an individual JSP. But when I am adding the JSP to a web project consisting of many other JSP pages, its not working.
    Do I have to change anything else.
    Please help me if you have any suggestions. I am eagerly waiting for any response.
    Thanks in advance.

    I used to have a similar problem. I have jsp pages in braz. portugese and for these I have    <meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1">When I tried setting the contentType to UTF-8, the way you wrote foreign characters didn't get submitted properly from input fields so I took it away, then everything worked correctly. Don't know why though.

Maybe you are looking for

  • How to check if the directory is created using create or replace directory

    Hello, I have create a directory as below: Create or Replace Directory TEST_DIR AS 'C:\ABCD' How to check if the directory is created or not? Is there any query for that? Thanks in advance. PK

  • How to view presentation in landscape mode?

    I just bought Keynote for iOS, to present some of my app mockups, but was sadly surprised to learn that I can't rotate a presentation to landscape mode. My canvas is 640x960. Anyone know if Apple is aware of this, or if there is a workaround? I had h

  • TS1424 Star Trek - into the darkness, Download error 8008

    I am unable to download this movie, it stops at 110MB with file is corrupt, try downloading again. Ive tried this 5 times now and ever time it gets to 110MB it stops? the Itunes extras for the film downloaded perfect about 2.3GB size. Ive even delete

  • Keep the files on my HD?

    I created an iWeb site, and i've put the pictures from my site in a folder on my HD. Is there a reason to store these photos? Or are they living somewhere else now, so that I can delete them from my HD? Thanks Danny http://web.mac.com/dbligh/iWeb/Sit

  • Validation of TLF-Markup with DTD?

    Hi everyone, we're using TLF to display structured text on the client side with Flex. The text comes from a database where it is stored in our own XML-Markup, transformed on the server side (java server) to TLF-Markup and then sent to the client. Is