Jpanel to a picture in Servlet without saving to disk

Hi. I need to display a graph on the fly in a servlet. I currently have the graph in a JPanel. I saw all the posts about how to save this to disk. Can anyone please suggest a way to display it (servlet generated HTML) without saving it to disk?
Any suggestions for a good tutorial on servlets serving generated images would also be highly appreciated.
Thank you very much,
Arijit

Hi,
I have an example that works with Java Server Faces based web components and produces svg dynamically. The same strategy can be used for jpg or any other graphical format.
* SessionServlet.java
* Created on June 3, 2004, 12:09 AM
package com.hypernex.xml.svg;
import java.io.*;
import java.net.*;
import javax.servlet.*;
import javax.servlet.http.*;
* @author  hyperdev
* @version
public class SessionServlet extends HttpServlet
    /** Initializes the servlet.
    public void init(ServletConfig config) throws ServletException
        super.init(config);
    /** Destroys the servlet.
    public void destroy()
    /** Processes requests for both HTTP <code>GET</code> and <code>POST</code> methods.
     * @param request servlet request
     * @param response servlet response
    protected void processRequest(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
        ServletContext context=getServletContext();
        java.util.Enumeration e=context.getServlets();
        while(e.hasMoreElements())
            System.out.println("servlets \t"+e.nextElement());
        /*e=context.getAttributeNames();
        while(e.hasMoreElements())
            System.out.println("AttributeNames \t"+e.nextElement());
        e=request.getParameterNames();
        while(e.hasMoreElements())
            System.out.println("ParameterNames \t"+e.nextElement());
        System.out.println("getContextPath "+request.getContextPath());
        System.out.println("getRequestURI"+request.getRequestURI());
        response.setContentType("text/xml+svg");
        PrintWriter out = response.getWriter();
        HttpSession httpSession=request.getSession();
        System.out.println("getQueryString"+httpSession);
        if(httpSession!=null && request.getRequestURI().endsWith("wafermap.svg"))
            /*e=httpSession.getAttributeNames();
            while(e.hasMoreElements())
                System.out.println("httpSession AttributeNames \t"+e.nextElement());
            SVGProducer svgProducer=(SVGProducer)httpSession.getAttribute("waferMap");
            out.print(svgProducer.getSVGView());
        else if(httpSession!=null && request.getRequestURI().endsWith("hardware.svg"))
            SVGProducer svgProducer=(SVGProducer)httpSession.getAttribute("hardwareBean");
            out.print(svgProducer.getSVGView());
        else if(httpSession!=null && request.getRequestURI().endsWith("geometry.svg"))
            SVGProducer svgProducer=(SVGProducer)httpSession.getAttribute("geometryBean");
            out.print(svgProducer.getSVGView());
        else
            try
                java.io.BufferedReader br=new java.io.BufferedReader(new java.io.FileReader("./webapps"+request.getRequestURI()));
                String line=null;
                while((line=br.readLine())!=null)
                    out.println(line);
                br.close();
            catch(java.io.IOException ioe)
                System.out.println("ioe:"+ioe.getMessage());
        out.close();
    /** Handles the HTTP <code>GET</code> method.
     * @param request servlet request
     * @param response servlet response
    protected void doGet(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
        processRequest(request, response);
    /** Handles the HTTP <code>POST</code> method.
     * @param request servlet request
     * @param response servlet response
    protected void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException
        processRequest(request, response);
    /** Returns a short description of the servlet.
    public String getServletInfo()
        return "SVG graphics handler";
}And any jsf component that implements
* SVGProducer.java
* Created on June 3, 2004, 9:09 PM
package com.hypernex.xml.svg;
* @author  hyperdev
public interface SVGProducer
    public String getSVGView();
}such as
public class WaferMap extends Object implements com.hypernex.xml.svg.SVGProducer
    protected void generateSVGWafermap(java.sql.ResultSet resultSet)
        //FacesContext context = FacesContext.getCurrentInstance();
        //context.
        //Create an svg graph of the equation.
        org.apache.batik.dom.svg.SAXSVGDocumentFactory svgFactory=new org.apache.batik.dom.svg.SAXSVGDocumentFactory("org.apache.xerces.parsers.SAXParser");
        org.apache.batik.dom.svg.SVGDOMImplementation svgDOMImplementation=new org.apache.batik.dom.svg.SVGDOMImplementation();
        org.w3c.dom.DocumentType dt=null;//svgDOMImplementation.createDocumentType("svg","-//W3C//DTD SVG 1.1//EN",f.toURI().toString());
        //System.out.println(dt);
        org.w3c.dom.svg.SVGDocument svgOMDocument=null;
        try
            System.out.println("dir "+(new java.io.File(".")).toURI().toString());
            java.io.File f=new java.io.File("./webapps/jsf-wita/siteadmin/templates/wafermap-template.svg");
            svgOMDocument=(org.w3c.dom.svg.SVGDocument)svgFactory.createDocument(f.toURI().toString(), new java.io.FileInputStream(f));//new org.apache.batik.dom.svg.SVGOMDocument(dt, (org.w3c.dom.DOMImplementation)svgDOMImplementation);
            org.w3c.dom.svg.SVGSVGElement root=svgOMDocument.getRootElement();
            org.w3c.dom.svg.SVGGElement visuals=(org.w3c.dom.svg.SVGGElement)svgOMDocument.getElementById("visuals");
            //visuals.getFirstChild().setNodeValue(Double.toString(xMin));
            //resultSet.beforeFirst();
            while(resultSet.next())
                org.apache.batik.dom.svg.SVGOMRectElement rect=new org.apache.batik.dom.svg.SVGOMRectElement("", (org.apache.batik.dom.AbstractDocument)svgOMDocument);
                rect.setAttribute("fill", "teal");
                rect.setAttribute("stroke", "teal");
                rect.setAttribute("transform", "scale(1, -1)");
                rect.setAttribute("stroke-width", "1");
                double x=50+100.0*(resultSet.getDouble("X")-2.5)/300.0;
                double y=100.0*((resultSet.getDouble("Y")-2.0)/300.0-0.5);
                //System.out.println(x+" "+y);
                rect.setAttribute("x", Double.toString(x)+"%");
                rect.setAttribute("y", Double.toString(y)+"%");
                rect.setAttribute("width", "10");
                rect.setAttribute("height", "8");
                visuals.appendChild(rect);
            javax.xml.transform.TransformerFactory tFactory = javax.xml.transform.TransformerFactory.newInstance();
            javax.xml.transform.Transformer intermediateTransformer=tFactory.newTransformer(new javax.xml.transform.stream.StreamSource("./webapps/jsf-wita/stylesheets/identity.xsl"));
            java.io.CharArrayWriter caw=new java.io.CharArrayWriter();
            intermediateTransformer.transform(new javax.xml.transform.dom.DOMSource(svgOMDocument), new javax.xml.transform.stream.StreamResult(caw));
            svgView=caw.toString();
        catch(java.sql.SQLException sqle)
            System.out.println("sqle err: "+sqle.getMessage());
        catch(javax.xml.transform.TransformerConfigurationException tce)
            System.out.println("tce err: "+tce.getMessage());
        catch(javax.xml.transform.TransformerException te)
            System.out.println("te err: "+te.getMessage());
        catch(java.io.FileNotFoundException fnfe)
            System.out.println("fnfe:"+fnfe.getMessage());
        catch(java.io.IOException ioe)
            System.out.println("io:"+ioe.getMessage());
    public String getSVGView()
        return svgView;
    private String svgView="";of course with jpg or other binary formats you would need to use a byte array instead of a string. Note that my example does take a template svg file which holds all the static parts and positions for dynamic parts, gets any changes from the data in a database, and creates an in memory svg to go to the client with any changes since the last request.
On a jsf/jsp/html page where there is
<embed src="../wafermap.svg" align="left" width="400" height="400" ...the server will supply the graphic via the SessionServlet

Similar Messages

  • Is there a way to import iMessage pictures to laptop without saving them to camera roll?

    I send all my pictures from my camera roll to iMessage as soon as I save them. I have over 1000 pictures on there. With out saving them to my camera roll again, is there a way to import them to my laptop? I can get my camera roll images onto my laptop, but not iMessage.I hope this makes sense.

    jemkat wrote:
    I send all my pictures from my camera roll to iMessage as soon as I save them. I have over 1000 pictures on there. With out saving them to my camera roll again, is there a way to import them to my laptop? I can get my camera roll images onto my laptop, but not iMessage.I hope this makes sense.
    Sorry, it doesn't make sense to me. Why would you want to send photos to iMessage that you have already saved to the camera roll and imported to your PC - just to send the same photos back to the PC again?

  • Display image in JPanel without saving any file to disk

    Hi,
    I am fetching images from database. I am saving this image, display in JPanel and delete it. But this is not actually I want.
    I wish to fetch this image as stream , store in memory and display in JPanel without saving any fiel in disk.
    I wonder if it is Possible or any used implementation that I can use in my project. Any idea or experienced knowledge is enough.
    Thanks

    In what format is the image coming to you from the database? If it's an InputStream subclass, just use javax.imageio.ImageIO:
    InputStream in = getImageInputStream();
    BufferedImage image = null;
    try {
       image = ImageIO.read(in);
    } finally {
       in.close();
    // ... Display image in your JPanel as you have beenIf you receive the image as an array of bytes, use the same method as above, but with a ByteArrayInputStream:
    byte[] imageData = getImageData();
    ByteArrayInputStream in = new ByteArrayInputStream(imageData);
    BufferedImage image = null;
    try {
       image = ImageIO.read(in);
    } finally {
       in.close();
    // ... Display image in your JPanel as you have been

  • How do I access pictures from my iPhone saved in iCloud so that I can delete some of them from iCloud selectively?.

    How do I access pictures from my iPhone saved in iCloud in a computer so that I can see & delete some of them from iCloud to free up the free 5GB?.

    What Mac model do you have? What system version and iPhoto version are you running?  Do you meet these requirements:
    The following is for this Apple document: iCloud: Photo Stream FAQ
    What do I need to use Photo Stream?
    To use Photo Stream, including Shared Photo Streams, you need an iCloud account, compatible devices, and up-to-date software:
    iPhone, iPad, or iPod touch with iOS 6.0 or later
    Mac with OS X Mountain Lion v10.8.2 or later and iPhoto 9.4 or Aperture 3.4 or later
    PC with Windows 8, Windows 7, or Windows Vista (Service Pack 2) and the iCloud Control Panel 2.1 or later for Windows
    Apple TV (2nd generation) with Software Update 5.1 or later
    You can still use Photo Stream without Shared Photo Streams if your devices meet these requirements:
    iPhone, iPad, or iPod touch with iOS 5.1 or later
    Mac with OS X Lion v10.7.5 or later and iPhoto 9.2.2 or Aperture 3.2.3 or later
    PC with Windows 7 or Windows Vista (Service Pack 2) and the iCloud Control Panel v2.0 or later for Windows
    Apple TV (2nd generation) with Software Update 5.0 or later
    If you do then sign in to the same iCloud account that's on your iPhone on your Mac via the System/iCloud Preference pane as shown in this screenshot:
    Next setup iPhoto's Photo Stream preference pane as shown in this screenshot:
    The photos on your iPhone must be in it's Photo Stream so make sure the iPhone has enabled Photo Stream as shown below:
    Now you can select a photo in the Photo Stream section of iPhoto and control-click on it to delete it:
    OT

  • Report without saving the records

    Hello all of you,
    i have a master detail block,, and i want to take a print from oracle report 6i without saving the record,, i just enter the record in the text boxes and then press the report button to generate the report
    i am using oracle forms and report 6i with oracle 9i database
    thanks in advance

    Hi i put the code for testing for one block and its not inserting the records and mainly its a non database block and i want to insert only the selected check box' record.I tried following code but its not inserting
    DECLARE
    Num_Tot NUMBER;
    Num_Loop NUMBER;
    BEGIN
    GO_BLOCK('FLX');
    LAST_RECORD;
    Num_Tot := TO_NUMBER(NAME_IN('SYSTEM.CURSOR_RECORD'));
    FIRST_RECORD;
    FOR Num_Loop IN 1..Num_Tot LOOP
    IF :TR.CHK = 1 THEN -- 1 is the value when checked.
    INSERT INTO REC_HIST
    values(:TR.RN_DT,:TR.AC,:TR.Amt,sysdate);
    commit;
    IF :SYSTEM.LAST_RECORD = 'TRUE' THEN
    EXIT;
    END IF;
    end if;
    NEXT_RECORD;
    END LOOP;
    end;
    rgds
    sandya
    Edited by: user10642220 on May 25, 2009 11:56 PM

  • Close Excel com object without saving changes?

    Hi, I am trying to write a script which opens each of 31 excel workbooks, retrieves a value from a cell, and closes each workbook after retrieving.
    My code so far:
    $day=1
    $excel = New-Object -ComObject Excel.Application
    $excel.Visible=$True
    $workbook= $excel.Workbooks.Open("C:\Path|to\File\1_"+$day+"_14.xlsx")
    $workbook.sheets.item(1).activate()
    $WorkbookTotal=$workbook.Worksheets.item(1)
    $value = $WorkbookTotal.Cells.Item(7,13)
    $value.Text #this should give you back the Value in that Cell
    $excel.close()
    My problem is that when the code hits the $excel.close() method, the file stays open, and prompts for saving changes.  I don't know why it thinks there are changes, but what I want is to close the workbook without saving changes.
    I've just closed 44 open browser tabs, and have tried many things over the last hour, but can't seem to get this one.
    If anyone has any advice on how to do this, it would be greatly appreciated!
    Thanks,
    Kevin

    Hi,
    Please replace below code:
    $excel.close()
    with
    $workbook.close($false)
    $excel.quit()
    Hope this helps.
    Regards,
    Yan Li
    Regards, Yan Li

  • I was trying to get the iOS 8.2 on my iPhone 5 but then it stopped and my phone is now on recovery mode I have pictures I need and they did not all fit on iCloud  how can I use the phone again with ALL my pictures and videos without restoring it?

    I was trying to get the iOS 8.2 on my iPhone 5 but then it stopped and my phone is now on recovery mode I have pictures I need and they did not all fit on iCloud  how can I use the phone again with ALL my pictures and videos without restoring it?

    Contacts are designed to be synced to a supported application on the computer or a cloud service.
    Pictures taken with the device are designed to regularly be copied off the device to a computer as would be done with any digital camera.
    If you have failed to use the device as designed it may be too late to recovery anything.
    Is the device regularly backed up to a computer via iTunes?  If so, the most recent backup (when restored to a replacement iOS device) should contain all contacts and pictures as of when the backup was created.

  • I want to use Thunderbird without saving e-mails to PC. How is this possible?

    I want to use Thunderbird without saving any e-mail to local folder in my PC.
    Can you please help me on this?
    thanks.

    There are two types - POP and IMAP
    You would need to logon to your webmail account using a browser and select the option to use IMAP forwarding - assuming that option is available.
    Pop mail accounts can only access the server Inbox.
    Emails are downloaded to your computer and stored in your Thunderbird Profile folder. So this type may not suit your requirements.
    IMAP mail accounts offer a remote view of folders and emails stored on the server.
    You subscribe to see those folders. Then Headers are downloaded and when you select to view an email, the email is downloaded to a temp cache.
    Subscribed folders that are synchronised, download a copy of the folder and store it in your Thunderbird Profile. But these folders are constantly updated to reflect what is stored on the server.
    So your best option would be to create IMAP mail account, subscribe to see folders on the server, but do not select to synchronise those subscribed folders.
    Emails stored in your Thunderbird Profile on your computer load faster than those that have to be retrieved from the server each time.
    Info on synchronising, so you can see how to enable/disable.
    * https://support.mozilla.org/en-US/kb/imap-synchronization

  • My old computer had itunes and downloaded songs that I put on my ipod. My old computer got replaced years ago without saving hard drive info or passwords and my iPod burnt out and will not activate. How can I get access to my old songs on new computer.

    My old computer had itunes and downloaded songs that I put on my ipod. Well, my old computer got replaced years ago without saving hard drive info or passwords and my iPod burnt out years ago and will not activate. I now have a new computer and iPod and I have an iTunes account on my iPhone5. How can I get access to my old songs on new computer? Are they lost for good? I have no info about my old computer and old account.

    Downloading past purchases from the App Store ... - Support - Apple

  • Using Firefox, I used to be able to open a document on a website and look at it without downloading.  Now, I must download a document in order to view it.  How can I change settings so that I can open documents without saving them?

    Using Firefox, I used to be able to open a document on a website, such as a bank statement, and view it without downloading.  Now, I must download and save a document before I can view it.  How can I change settings so that I can open documents without saving them first?

    Do you know what kind of docs they are? Did you upgrade/Update Firefox lately?
    https://addons.mozilla.org/en-US/firefox/addon/pdf-download/
    http://kb2.adobe.com/cps/333/333563.html
    https://addons.mozilla.org/en-US/firefox/addon/open-it-online/

  • Creating a Mavericks USB boot drive after the horse has bolted.  Can I create a bootable USB drive from my iMac after installing Mavericks without saving the Install OS X Mavericks.app file?  Do I need to re- download the whole 5.29 Gb again?

    Creating a Mavericks USB boot drive after the horse has bolted.  Can I create a bootable USB drive from my iMac after installing Mavericks without saving the Install OS X Mavericks.app file?  Do I need to re- download the whole 5.29 Gb from the App Store again?  My problem is my 4Gb/month allowance on a 12 month contract.  I cannot purchase a data block from my ISP and although my speed is theoretically slowed to 64k after reaching my 4Gb, it actually ceases to download in reality.

    HI tasclix, it depends what you mean by an OS X boot drive.
    If you want a recovery disk from which you can reinstall (by re-downloading) or recover from a time machine backup, then nbar is correct.
    If, however, you want to boot and run the OS X installer from the USB drive (so that you don't need to download again), then you will need a copy of "Install OS X  Mavericks.app"; see this article:
    http://support.apple.com/kb/HT5856
    Before downloading again, search your system to see if the installer is still there - it's usually in the /Applications folder unless it has been deleted, but check your whole system for it anyway, you never know, you might still have it somewhere.
    Message was edited by: SilverSkyRat

  • Insert picture and sound without external sources

    how can we insert pictures and sound without using external sources??
    i mean , i want to make the picture somehow embeded inside the program, not from external source,
    can any1 help?/

    I sense that what you need to do is create a Jar (java archive) file for your code and images and any other resources. Do a search on the forum for the terms -- jar pictures getresource -- and you'll get a ton of helpful threads. Also check Google. Some useful links:
    http://java.sun.com/docs/books/tutorial/deployment/jar/
    http://forum.java.sun.com/thread.jspa?forumID=54&threadID=5183949
    http://www.cs.princeton.edu/introcs/85application/jar/jar.html

  • How can I get Firefox to directly open a file (like a torrent) without saving it at all

    It seems that up until about 3 months ago - I could get firefox to download a file and open it directly without saving it to any particular place. This is particulary useful for downloading say a torrent or, for that matter, any other file I wish to use within another program but do not need to save the file.
    Now I have to download the file, chose where it will be saved, open the folder click on the file, and then delete the now un-needed file. A huge hassle.
    I am sure I could do this until a few months ago. For some reason I cannot now.
    Please help

    Make sure that the file has the .html file extension.
    That should be sufficient.
    Windows hides some file extensions by default.
    Among them are .html and .ini and .js and .txt, so you may only see file name without file extension.
    You can see the real file type (file extension) in the properties of the file via the right-click context menu in Windows Explorer.

  • How do I prevent the "Save as" window that started popping up yesterday and just print articles without saving?

    In years of printing articles I could always print without "saving as" first. Is there some setting I need to change or an add-on? I have firefox 3.6.13, Windows XP, HP PSC 2355

    {Ctrl + P} or File > Print
    Is your printer selected at the top in Printer - Name??
    Is '''Print to File''' selected on the right, a little further down??

  • How do I print Mail attachment without saving it first

    I'm new to Mavericks.  With Mail in Lion, I could scroll to the bottom of an email and double click on the icon for the Word doc or pdf attachment to open it, then hit command P to print it. With Mavericks, it appears that I have to first "save" the document somewhere and then open it and print it. Is this correct?
    In most cases, this is an extra step that is unnecessary.
    Right now, the attachment displays (opened) within the email, but I don't want to print several pages of an email when all I want is to print the attached doc, for instance, an attached invoice. Also, I can't tell what kind of document it is without saving it, which I don't like. I've tried to find a way around this in preferences but no luck.
    I guess what I'd really prefer is to go back to the old Lion version of Mail, or something that approximates it more closely. Do I need to just get over it and realize that I'm going to have to save every attachment if I want to print it or is there a workaround of some sort?

    Hi tbirdvet. Even though the content of the attachment now displays as part of the email message, I tried clicking on that portion of the email and, sure enough, the "attachment" popped up in Preview, just like you said. (I kept looking for a Word doc icon or a pdf icon to double click on, but they're no longer found at the bottom of the email or selectable from a drop down menu.)
    I'm so glad this worked. Thanks.

Maybe you are looking for