Show several gifs files using servletOutputstream

Hello,
I'm trying to display several gifs files in a html file. I extract all the files from an oracle database. I'm trying to use a servletoutputstream, but it does not difference between text and image.
Process:
1. Select html file from database
2. Go through each line of html file to find the links to gif files
- if gif :
3. Ask for the gif file detected and select from database
4. use servletoutputstream to display the file
- end of if
-else
5. display the line of text.
Is it possible to use a servletoutputstream to display several gifs and text content?
Is there one other solution to do it correctly?
Thanks in advance,
Angela.
The code I use is:
private void retrieveFile()
FileWriter fwHtml=null;
oracle.sql.BLOB blob=null;
InputStream in=null;
ServletOutputStream out=null;
ResultSet rsGif=null;
try
//Extract html file from the database
String query="SELECT * FROM DBFiles WHERE FILENAME='"+file+"'";
PreparedStatement ps = connection.prepareStatement (query);
ResultSet rs=ps.executeQuery();
rs.next();
String fileName=rs.getString("FILENAME");
if (fileName.indexOf("html")!=-1)
InputStream fis=rs.getAsciiStream(5);
//I read each line to know where the html file calls the links to the gif files
BufferedReader reader= new BufferedReader(new InputStreamReader(fis));
String line;
String mimeType="";
try{
while ((line=reader.readLine()) !=null)
if((line.indexOf("img src="))!=-1)
int imgIndex=line.indexOf("img src=");
int altIndex=line.indexOf(" alt=");
//I obtain the name of the gif file that I obtain from the database
String gifFile=line.substring(imgIndex+9,altIndex-1);
query="SELECT * FROM DBFiles WHERE FILENAME='"+gifFile+"'";
ps.clearParameters();
ps = connection.prepareStatement (query);
rsGif=ps.executeQuery();
rsGif.next();
blob=((OracleResultSet)rsGif).getBLOB("GIF");
String gifName=rsGif.getString("FILENAME");
mimeType = context.getMimeType(gifName);
response.setContentType(mimeType);
out = response.getOutputStream();
in=blob.getBinaryStream();
int bufferSize=blob.getBufferSize();
byte[] buffer = new byte[bufferSize];
int bytesRead=0;
int intBuffer=in.read(buffer);
while ((bytesRead=intBuffer)!= -1)
out.write(buffer,0,bytesRead);
in.close;
else
byte[] bString =line.getBytes();
mimeType = context.getMimeType(fileName);
response.setContentType(mimeType);
out.write(bString,0,line.length());
catch (IOException ioe) {
System.out.println("Unable to open Image file "); ioe.printStackTrace();
finally {
if (out != null) {
out.flush();
out.close();
ps.clearParameters();
connection.commit();
rsGif.close();
rs.close();
ps.close();
catch (SQLException sqle)
sqle.printStackTrace();
catch (Exception e)
e.printStackTrace();

I may be wrong, but I don't think HTML supports inlining image data for a page. I think you need to let the client process the HTML and make requests to your servlet for specific images; it is at this point they should be read from the database and returned to the client.
So I'll change your algorithm to
1. Select html from the database
2. Return it to the client
3. Client makes request for an image (<img src="servlet?image=name">) maybe
4. Servlet reads image from the db
5. Servlet set appropriate header information (image/gif etc)
6. Servlet outputs image data.

Similar Messages

  • Display gif files using servletoutputstream (again)

    Hello,
    I'm trying to display several gifs files in a html file. I extract all the files from an oracle database. I'm trying to use a servletoutputstream, but it does not difference between text and image.
    Process:
    1. Select html file from database
    2. Go through each line of html file to find the links to gif files
    - if gif :
    3. Ask for the gif file detected and select from database
    4. use servletoutputstream to display the file
    - end of if
    -else
    5. display the line of text.
    Is it possible to use a servletoutputstream to display several gifs and text content?
    Is there one other solution to do it correctly?
    Thanks in advance,
    Angela.
    The code I use is:
    private void retrieveFile()
    FileWriter fwHtml=null;
    oracle.sql.BLOB blob=null;
    InputStream in=null;
    ServletOutputStream out=null;
    ResultSet rsGif=null;
    try
    //Extract html file from the database
    String query="SELECT * FROM DBFiles WHERE FILENAME='"+file+"'";
    PreparedStatement ps = connection.prepareStatement (query);
    ResultSet rs=ps.executeQuery();
    rs.next();
    String fileName=rs.getString("FILENAME");
    if (fileName.indexOf("html")!=-1)
    InputStream fis=rs.getAsciiStream(5);
    //I read each line to know where the html file calls the links to the gif files
    BufferedReader reader= new BufferedReader(new InputStreamReader(fis));
    String line;
    String mimeType="";
    try{
    while ((line=reader.readLine()) !=null)
    if((line.indexOf("img src="))!=-1)
    int imgIndex=line.indexOf("img src=");
    int altIndex=line.indexOf(" alt=");
    //I obtain the name of the gif file that I obtain from the database
    String gifFile=line.substring(imgIndex+9,altIndex-1);
    query="SELECT * FROM DBFiles WHERE FILENAME='"+gifFile+"'";
    ps.clearParameters();
    ps = connection.prepareStatement (query);
    rsGif=ps.executeQuery();
    rsGif.next();
    blob=((OracleResultSet)rsGif).getBLOB("GIF");
    String gifName=rsGif.getString("FILENAME");
    mimeType = context.getMimeType(gifName);
    response.setContentType(mimeType);
    out = response.getOutputStream();
    in=blob.getBinaryStream();
    int bufferSize=blob.getBufferSize();
    byte[] buffer = new byte[bufferSize];
    int bytesRead=0;
    int intBuffer=in.read(buffer);
    while ((bytesRead=intBuffer)!= -1)
    out.write(buffer,0,bytesRead);
    in.close;
    else
    byte[] bString =line.getBytes();
    mimeType = context.getMimeType(fileName);
    response.setContentType(mimeType);
    out.write(bString,0,line.length());
    catch (IOException ioe) {
    System.out.println("Unable to open Image file "); ioe.printStackTrace();
    finally {
    if (out != null) {
    out.flush();
    out.close();
    ps.clearParameters();
    connection.commit();
    rsGif.close();
    rs.close();
    ps.close();
    catch (SQLException sqle)
    sqle.printStackTrace();
    catch (Exception e)
    e.printStackTrace();

    Let's put it this way, since I don't have the patience to look at your code. HTML cannot have images embedded in it, it can only have links to images. So you could have a servlet that sends an image, but only a single image and nothing else. I see you have code to set the MIME type of the image, so I don't have to tell you about that.

  • How to edit existing gif file using photoshop (CS2)

    Hello Forum,
    I have some gif images that I have used for creating tabs on a
    web page. I downloaded these images from somewhere, and did not create them
    myself. I would like to change the color of these gif files.
    They are a nice image, with a gradient applied at the top, and I have a left side gif for the tab as well as an "over" image set for the tab(s) as well.
    I use the images in a css file to display the tabs on a web page.
    The gradient is across the top of the tab, which is a lighter color, almost going to white, and the rest of the tab is a light blue, with left and right top a slight rounded corner. I would like to preserve the gradient appearance, but change the light blue theme to an almost black (#333333) color.
    How can I do this in photoshop?
    Thanks,
    eholz1

    Hi All
    I would like to create an action in CS2 to resize an image to e.g 600 x ? pixels and then save for web at max 149kb .
    Any clues? I've tried a few different files of different file sizes?(possible cause here) and always end up with different results when using my actions or the image processor.
    Is this at all possibleto accomplish in a single step?
    Let me elaborate more. On a particular forum where post we are limited to 600 x? pixels and file size no greater than 150 kb. When creating this action in CS2 with different file sizes one lands up with files ranging from 70kb (not as good for viewing) to 149kb(perfect size)or 357kb?(way too big). I'd like to have as close to <150kb for ALL files in the "action"
    Is this possible without getting into scripting?
    Thanks
    Don

  • Need a way to request for a web resource (e.g .css, .gif file) using jpdk

    I am wondering if there is any way by which we can request for a web resource from portal to portlet provider.
    Currently if in order to display image I need to make direct request to portlet provider rather than routing the request through portal. As a result of this there is no session affiliation.
    My web resource can also be .jsp or .html file
    Any suggestions are welcome.

    Hi Hernando,
    It seems I haven't put my question correctly, probably following might help me explain you what I require:
    Portlets are added to portal page. Portlet content is served by portlet provider. So when you are viewing a portal page containing portlets in reality portal requests the portlet data from portlet-provider. So the actual request flow is: Request for a portal page, portal analyzes portlets on the page, and then request the portlet provider for the content associated with portlet. In the exact reversal process data flow is: portlet-provider generates the content which is passed to portal & then portal forwards it to end user.
    Now want something similar to happen with images (.gif files). But the problem is I am failing to create a link for this resource. I want the request for image to flow through portal very much the same way as its doing for the content. In other words I want to create a link which would inform portal to request for the resource to portlet provider. In this scenario portlet provider would pass the image to portal which would be forwarded to end user. Currently to get the images I am making direct request to portlet provider there by bypassing the request to flow through portal, which I do not want. Above all this resource can be anything a css file or a image or a .js file.
    So can you suggest me how to achieve it?

  • How to receive a gif file using a custom ABAP FM

    Hi Experts,
              Here is my requirement.
              I have to provide an interface which should receive a GIF file.
              I have created a FM but what data type should I define in the import parameter or the table parameter to receive the GIF file (which has been converted to binary format by the other application).
    Thanks in advance.

    Hi,
       Do not type it to any associated type.
    Create a tables parameter with some name.
    Actually the FM GUI_UPLOAD does the same thing(Just that it is not RFC enabled).
    YOu can check its code.
    Regards,
    Ravi

  • How to split a big file into several small files using XI

    Hi,
    Is there any way to split a huge file into small files using XI.
    Thanks
    Mukesh

    There is a how to guide for using file adapters, an "sdn search" will get you the document.
    Based on that , read a file into XI, Use strings to store the file content and do the split
    here is some code to get you started
    ===========
    Pseudocode:
    ===========
    // This can be passed in - however many output files to which the source is split
    numOutputFiles = 5;
    // Create the same number of filehandles as numOutputFiles specifies
    open file1, file2, file3, file4, file5;
    // Create an Array to hold the references to those filehandles
    Array[5] fileHandles = {file1, file2, file3, file5, file5};
    // Initialize a loop counter
    int loopCounter = 0;
    // a temporary holder to "point" the output stream to the correct output file
    File currentOutputFile = null;
    // loop through your input file
    while (sourceFile.nextLine != null)
    loopCounter++;
    if (loopCounter == (numOutputFiles +1) // you've reached 5, loop back
    loopCounter = 1;
    currentOutputFile = fileHandles[loopCounter]; // gets the output file at that index of the array
    currentOutputFile.write(sourceFile.nextLine);
    regards
    krishna

  • Powe point: NOT SHOWING ANIMATED GIF FILES

    WHEN I SAVE A SLIDE SHOW IN PPS FORMAT THE GIF IMAGES DO NOT HAVE ANY MOVEMENT. IM WORKING IN OFFICCE 2008, MY SYSTEM IS 10.5.5 AND AS I PUT THEM IN ENTOURAGE ALSO DO NT MOVE. CAN SOMEBODY HELP ME, PLEASE

    Please don't type in all capital letters - it is hard to read and construed as shouting. Microsoft has its own forums here. That's probably where you'll have the best shot at getting the question answered.

  • How to display several several gif as splash screen continuously?

    like title said, I want to display several gif files as splash screen so that it looks like animation, how to do that? the splash.java that I uses can only display one picture. what I would like to see is something that display several pictures in the same location on screen, one disappear after another show up without gap in between so that the user won't realize that it's several picture together.
    just ignore the PV, I use splash to start my main.
    class Splash extends JWindow {
         public Splash(String filename, Frame f, int waitTime) {
              super(f);
              JLabel l = new JLabel(new ImageIcon(filename));
              getContentPane().add(l, BorderLayout.CENTER);
              pack();
              Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
              Dimension labelSize = l.getPreferredSize();
              setLocation(screenSize.width / 2 - (labelSize.width / 2), screenSize.height / 2 - (labelSize.height / 2));
              addMouseListener(new MouseAdapter() {
                   public void mousePressed(MouseEvent e) {
                        setVisible(false);
                        dispose();
                        PictureViewer PV = new PictureViewer();
              final int pause = waitTime;
              final Runnable closerRunner = new Runnable() {
                   public void run() {
                        setVisible(false);
                        dispose();
                        PictureViewer PV = new PictureViewer();
              Runnable waitRunner = new Runnable() {
                   public void run() {
                        try {
                             Thread.sleep(pause);
                             SwingUtilities.invokeAndWait(closerRunner);
                        } catch (Exception e) {
                             e.printStackTrace();
                             // can catch InvocationTargetException
                             // can catch InterruptedException
              setVisible(true);
              Thread splashThread = new Thread(waitRunner, "SplashThread");
              splashThread.start();

    Here is something like you want I thanks? you just have to add it to your splash screen.it is useing a jframe here
    import javax.swing.*;
    import java.awt.*;
    import java.util.*;
    public class ball extends JFrame implements Runnable{
      Image a,b,c,d,e,f,gg,pics;
      boolean go = true;
      int i,j = 0;
      Thread runner;
      Toolkit kit;
    public ball() {
       super();
       setSize(400,400);
       setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
       runner = new Thread(this);
       kit = Toolkit.getDefaultToolkit();
        a = kit.getImage("pic1.gif");
        b = kit.getImage("pic2.gif");
        c = kit.getImage("pic3.gif");
        d = kit.getImage("pic4.gif");
        e = kit.getImage("pic5.gif");
        f = kit.getImage("pic6.gif");
        gg = kit.getImage("pic7.gif");
       runner.start();
       setVisible(true);
      public void run() {
       Thread thisthread = Thread.currentThread();
        while(runner == thisthread) {
         repaint();
         try {
         i++;
         j++;
         if(i > 7){ i = 0;}
          if(i == 0){pics = a;  }
          if(i == 1){pics = b;  }
          if(i == 2){pics = c;  }
          if(i == 3){pics = d;  }
          if(i == 4){pics = e;  }
          if(i == 5){pics = f;  }
          if(i == 6){pics = gg;  }
          if(j > 100){ runner = null;}
         Thread.sleep(50);}
         catch(InterruptedException in) {}
      public void paint(Graphics g) {
       g.drawImage(pics,50,50,100,100,this);
    public static  void main(String[] args) {
        ball be = new ball();
    }good luck

  • Gif file not found in JAR from Java Application

    Hello Forumers,
    Could some one please explain how to create a JAR file from where I can get a GIF file. I have tried a number of different ways but it allways fails. (I have tried to add the GIF files using the jar command and I have tried to add it using WinZip after the jar is created).
    To isolate the problem I created this very simple program, the program works very well when the gif file resides on the directory from where I run the Application, but when I remove it from the directory it fails. I have tried to put the GIF file in the JAR in a number of different ways but it allways fails. (I have also tried with and without slash before the name of the GIF). I guess the problem is the way I create the JAR file
    import java.io.*;
    public class GifTest
    { public static void main(String args[])
    { InputStream in = GifTest.class.getResourceAsStream("/open.gif");
    if (in==null)
    System.out.println("Null returned");
    else
    System.out.println("OK");
    Any Hints appreciated
    /Kjell

    Hi,
    here is a small application using my own class GetImageIcon.
    Normally I have this "help-class" in a utility-package to use it from all my projects without copying. For this example I copied the code in the test application. Feel free to use the code of the class like you want. For me it works fine.
    Do the following:
    1. Create a folder called /meta-inf under the folder where the class-files are. Use a text-editor and create a file saved as "manifest.mf".
    manifest.mf tells the jar-file which is the main-class from where the application will start when double-clicked.
    It only has to contain one line:
    Main-Class: GifTest
    2. Compile and create the jar file. I made a bat-file containing:
    javac -verbose GifTest.java
    %pause
    REM Create Jar-File
    jar cmf meta-inf/manifest.mf GifTest.jar *.class *.gif
    REM Show Table of Content of the Jar-File
    jar tf GifTest.jar
    %pause
    So you can see what's in the jar-file.
    3. When you double-click on the jar-file the application is executed. So it is easier to use for the users. They don't have to type in anything on the command-line. You can deploy this jar-file to any client and run it. The only thing you have to do, is to install the JRE on the clients.
    I develop with JDK 1.3.1 and JRE 1.3.1 is installed on the clients of the company I work for.
    //Begin of the code
    import java.io.*;
    import java.awt.*;
    import javax.swing.*;
    import java.util.jar.*;
    public class GifTest extends JFrame
            protected JLabel m_title;
            protected ImageIcon m_image;
            static File file;
            //You have to define the name of the jar-file
            static String jarFile = "GifTest.jar";
            //Instance of the class GetImageIcon
            protected GetImageIcon gii = new GetImageIcon();
            public GifTest()
                    super("GifTest");
                    setSize(400,200);
                    //the name of the image and the name of the jar-file the image resides in
                    m_image = gii.getImageIcon("orb.gif", "GifTest.jar");
                    m_title = new JLabel(null, m_image, SwingConstants.CENTER);
                    getContentPane().add(m_title, BorderLayout.NORTH);
            public static void main(String argv[]) {
                    GifTest frame = new GifTest();
                    frame.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE);
                    frame.setVisible(true);
    public class GetImageIcon{
    * @param fileName the full qualified name of the file
    * from the root of your application. use a "/" before the
    * fileName, eg. /images/warning.gif
        public ImageIcon getImageIcon(String fileName, String jarName) {
            int counter, c, i = 0;
            byte buffer[];
            JarFile  jfile;
            JarEntry jentry;
            InputStream in;
            ImageIcon m_image;
            try{
                    // Create Jar-File object from JarFile
                    jfile = new JarFile(jarName);
            catch(Exception ex){
                    System.out.println("JarFile-Problem " + "\n" + ex);
                    return null;
            try{
                    // create Jar-Entry object from File-Name in JarFile
                    jentry = jfile.getJarEntry(fileName);
            catch(Exception ex){
                    System.out.println("JarEntry-Problem " + "\n" + ex);
                    return null;
            try{
                    // create InputStream from JarEntry
                    in = jfile.getInputStream(jentry);
            catch(Exception ex){
                    System.out.println("JarEntry-Problem " + "\n" + ex);
                    return null;
            try{
                    //get uncompressed size of entry data in Jar-File and create byte-array with this size
                    buffer = new byte[(int)jentry.getSize()];
                    //write int-value 'c' (casted to byte) with read() and while-loop in byte-Array
                    while((c = in.read()) != -1){
                            buffer[i] = (byte)c;
                            i++;
            catch(Exception ex){
                    System.out.println("in.read()-Problem " + "\n" + ex);
                    return null;
            try{
                    //create ImageIcon with byte-Array 'buffer'
                    m_image = new ImageIcon(buffer);
            catch(Exception ex){
                    System.out.println("ImageIcon-Problem " + "\n" + ex);
                    return null;
            // return the created ImageIcon
            return m_image;
    }

  • Is there support for animated .gif files?

    Is there support for animated gif files using
    form builder? I can't get it to work.
    Thanks
    Sean
    I am using forms 6.0

    She used the Link Tool, specfied 'Image URL' as the Source File Format and the url of the animated GIF in the Source Filename. Hope that helps.
    Makes sense but the form is not for the web.
    I have looked at doing it with timers and switching canvases, but that is just too much
    for sloppy animation. It's just not tight enough.
    Thanks,
    Sean
    null

  • .gif files can I mak them?

    I want to create my own Icons. Can I make my own .gif files using Java graphics? I know how to make a .java file using java; can I convert this to a .gif file so I can add it to my Java program as a Icon or .gif file?
    For example,
    cutAction.putValue(Action SMALL_ICON, new ImageIcon("cut.gif"));I want to be able to design my own .gif like the "cut.gif" in the preceding code. I want to do this using Java graphics. Can I simply make a .java graphics panel and save it as a .gif? This question might be pretty far off but I just need a push in the right direction to get the wheels rolling. If anybody could give me a hand the help would be much appreciated.

    Does PNG format support compression in general, and
    how can you achive this with ImageIO in particular?1) Yes.
    2) Apparently it can't.
    Here's how I found out:import java.util.*;
    import javax.imageio.*;
    public class TestPngImageWriter {
      public static void main(String[] argv) {
        Iterator i = ImageIO.getImageWritersBySuffix("png");
        while(i.hasNext()) {
          Object o = i.next();
          Class c = o.getClass();
          System.out.println(c.getName());
          showParam((ImageWriter) o);
      private static void showParam(ImageWriter iw) {
        ImageWriteParam iwp = iw.getDefaultWriteParam();
        System.out.println("WriteParam:\n  " + iwp);
        System.out.println("It " + (iwp.canWriteCompressed() ? "CAN" : "can NOT") +
    " write compressed images.");
    }That's with JDK 1.4.2. 1.5 may do better. Otherwise, it seems like an enhancement request is in order.

  • What is the problem when opening jpg files using Desktop API

    Hi, i would like to open jpg, or gif files using Desktop API, and the application crashes.The Desktop API is supported by my OS, because txt files, or file directories can be opened, mails can be sent, browsing is also supported.
    Only jpg and gif, and i think other picture formats cannot be opened.
    Obviously ACDSee and other picture viewing programs are installed in my computer.
    The corresponding application code can be found at the bottom of the page of http://www.awprofessional.com/articles/article.asp?p=661371&seqNum=2&rl=1
    my code:
    if(Desktop.isDesktopSupported()){
    Desktop desktop=Desktop.getDesktop();
    try
    desktop.open (fileToOpen);
    catch (IOException ioe)
    JOptionPane.showMessageDialog (frame,
    "I/O problem");
    catch (IllegalArgumentException iae)
    JOptionPane.showMessageDialog (frame,
    "File doesn�t exist");
    fileToOpen is obviously a File.
    Thx for the help in advance.
    Message was edited by:
    javahelps
    Message was edited by:
    javahelps
    Message was edited by:
    javahelps
    Message was edited by:
    javahelps

    My file association for jpg files is correct, if i click on a
    jpg, ACDSee starts immediately.Although I am a long time Windoze non-user, I vaguely remember that there's a difference between correct file-type association being set and some application starting at a mouse click on a file icon. I also vaguely remember Windoze file-type association mechanism uses a few action-types. Java Desktop should expect a specific action-type for the association.

  • Gif file location

    Can someone tell me what folder (or table) that the gif files used by the HTMLDB app are stored? Specifically, I'm looking for the create_flow.gif and the provisioning_reports.gif.
    Thanks in advance...

    oracle_home/HTTP/apache/apache/images/<br><br>
    You can find create_flow.gif there.<br><br>
    provisioning_reports.gif is in (starting at path above) themes/theme_5<br><br>
    chet

  • Showing tiff files using web.show_document

    Hello,
    I want to show tiff files using web.show_document. Tiff files cannot be displayed in a browser, however therr are several plug-ins available to show them.
    Can anyone recommend a plugin to display tiff files in a browser?
    Kind Regards Erik

    We had tried a different approach. We store all type of documents in the database using webutil.
    And we dont directly open any document and we download the document to the local host and then open it using webutil client host ('local folder\file name')
    This way word,excel, pdf etc will be automatically opened with its relevant appln and if there is relevant appln is not found it will prompt the windows standard Open with dialog box.
    Rajesh ALex

  • GIF file shows up fuzzy and pixelated on Dreamweaver

    I am trying to load a GIF file in Dreamweaver. I am saving it on Photoshop as an Unnamed GIF file with no dither, no transparency, and 128 colors. When I load the file onto Dreamweaver, it shows up fuzzy and pixelated. I know I am not stretching the image in dreamweaver, and I have saved the file as a PNG also and I get the same result. I think I am saving the file the wrong way but I am not sure what to do. I have an example of what the logo looks like on Dreamweaver.  Any suggestions?

    Image attachments tend to get lost in the Adobe queue forever.  Best to show us a URL to your page and image so we can look at the properties.  Or use the camera icon to insert your web image directly into your message.
    Dreamweaver rendering isn't what counts.  It's how your image looks in the major browsers.
    Did you convert CMYK to RGB?  Browsers don't support CMYK. Possibly gif isn't the right file type for your image.  Did you try saving for web as an optimized jpg?
    Nancy O.
    Alt-Web Design & Publishing
    Web | Graphics | Print | Media  Specialists
    www.alt-web.com/
    www.twitter.com/altweb

Maybe you are looking for