Image in a JSP

Hi all,
I need to clear something in my mind, obvioulsy I am missing the whole picture. When I write an html page, I can have an image stored somewhere in my C drive, and then with the "img" tag, I can ask my browser to display it.
When I want to do the same thing in a JSP page, for example having <img src="1.jpg"> in my JSP, where should the image be saved?
Thanks

Thank you very much for your reply, problem solved. I am using NetBeans and I have been saving the images in the wrong web directory. I didn't understand your last sentence though; "The URL in the src attribute must be relative to the current request URL". What is the current request URL?
Thanks again

Similar Messages

  • How to upload a image file using JSP

    hello to all.
    i am in the learning stage please help me to upload a image file
    using jsp. give the explanation to the code also if possible.
    thanks in advance
    sincerely
    Chezhian

    You may find the following articles useful for the JSP/Servlet part:
    Uploading files: http://balusc.blogspot.com/2007/11/multipartfilter.html
    Downloading files: http://balusc.blogspot.com/2007/07/fileservlet.html

  • How do you reference image files in jsp which becomes a portlet ?

    My portlet is a servlet managing jsp pages. In each of the jsp s, there are image files (*.gif) being referenced. I have placed the image files in .../public_html/WEB-INF/images/ in explorer. In my jsp, I am referencing the image file as
    src="WEB-INF/images/help.gif"
    On deploying my portlet, the image is not being picked up by the portal. Also, on moving the image and modifying the reference to it, I am still getting the same problem.
    Can anyone advise, for my portlet to display the image correctly,
    1) where should I place the image files ?
    2) how should the jsp code reference it ?
    Cheers,
    Tara

    Hi,
    The behaviour you are reporting is an expected behaviour. If you want to include images in your JSP, you need to specify the complete absolute URL to the image on the midtier as only then can the portal invoke that image.
    Actually, when you specified the relative URL
    WEB-INF/images/help.gif, Oracle9iASPortal actually looks for the image help.gif in the directory structure WEB-INF/lib at its end. As no such file exists, the images are not rendered onto Oracle9iASPortal page.
    So you got to use the following workaround,
    Assuming your provider name is "temp" (deployed using temp.ear) & the image name is "help.gif" which is stored in the htdocs folder inside temp. This image is invoked by help.jsp
    You can get the absolute path of this image as follows:
    Request URL is : http://<host>:<port>/temp/providers/temp
    Request URI is : /temp/providers/temp
    So, Base URL = http://<host>:<port>
    Servlet Path is : /temp/htdocs/help.jsp
    Truncating the Servlet Path to /temp/htdocs & appending this to Base URL should give you
    http://<host>:<port>/temp/htdocs
    which is the directory that contains your image. add image name to this URL to get the absolute p[i]Long postings are being truncated to ~1 kB at this time.

  • Displaying a image in a JSP

    I want to display a jpg image in a jsp I have added the line
    <img src = “img/backImage.jpg”>
    Into the body of my jsp page.
    I have placed the backImage.jpg into a folder called img which is in the WEB-INF folder.
    When I run the application the picture does not display.
    Do I have to configure the application to find the folder?
    Full code is below.
    Thanks
    <%@page contentType="text/html" pageEncoding="UTF-8"%>
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
       "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>JSP Pageeee</title>
        </head>
        <body>
            <img src="img\backImage.jpg" alt="Angry face" />
        </body>
    </html>

    The WEB-INF folder is not the root of your web application - the parent directory is. Move the img folder up one level to be a sibling of WEB-INF.
    <img src="img\backImage.jpg" alt="Angry face" />and the web isn't Windows - your backslash won't work well.

  • Dynamic Image rendering on JSP page

    Hi All!
    I want to display images on my JSP page. However, the images should be generated dynamically (As are used by many sites during the registration process e.g., yahoo, etc..) How can i achieve this?
    plz help! Its urgent!

    Yes, but your in the wrong forum for this.
    Use the search bar to look for posts and have a look in
    http://forum.java.sun.com/forum.jspa?forumID=5
    There are forums on Multimedia which may also have some information.

  • Displaying Image on th JSP page

    Hello All,
    I am using following code to display the image on the JSP page in my iView
    <% String PublicURL = componentRequest.getPublicResourcePath()+ "/images/Image1.gif"  ; %>
    <hbj:image id="Logo" width="70" height="35" 
                               src="<%= PublicURL %>"
                               alt= "picture Ericsson.gif" />
    Am I missing anything. I am still not able to display the image.
    Regards,
    Sanjeev

    change
    componentRequest.getPublicResourcePath()
    to
    componentRequest.getWebResourcePath()

  • How can I add an Image to a jsp from different paths???

    Hi,
    I am trying to include an image to my jsp from a directory which is not located under my jsp's directory. In other words, is it possible to put my jpeg file whereever I want in my C folder and still be able to add it into my jsp?
    Thanks,
    Alex

    That is not quite right. The image must be in a directory that is under the web server's view. JSP has nothing to do with images, the browser loads images separately after parsing the HTML results to find out what images it has to load. The images must be in a place that is servable by the web server being used.
    If you were just using Tomcat as a web server, then you would have a web application directory "myapp". The images need to go under "myapp" or in any subdirectory, except the WEB-INF directory, which is a special case.

  • Crystal Report Images Not Showing - JSP inside /WEB-INF folder

    Hi Experts,
    I am using Crystal report for Eclipse and also using Struts2 and tiles framework combination.
    The problem is when viewing the report all I've got is red X on all images and the graph image also not showing. This is when I use tiles and my jsp is inside the web-inf folder.
    This is my struts link: href="s:url value='/report/reportOpen.action?report=1'
    I've checked that the path to the viewer generated HTML is not correct. see code below.
    src="../../../crystalreportviewers/js/crviewerinclude.js"
    But when I test to access a simple jsp viewer that resides on the web root folder, this works fine but of course this is not what I want to have. I need to have my banner and menus on top of the report page (using tiles)
    This is my jsp link: href="s:url value='/ReportViewer.jsp?report=1'
    Viewer generated HTML below.
    src="crystalreportviewers/js/crviewerinclude.js"
    This might be a common problem and that you can share to me your solution.
    Note: I removed the script tags because I can't submit this entry.
    Thank you  in advance,
    Regards,
    Rulix Batistil
    Crystal Report Images Not Showing - JSP inside /WEB-INF folder

    Hi Saravana,
    After a few experimentation from your idea i was able to figure out the problem and now it is working.
    I don't have to copy the folder to where my jsp resides but still maintains it in the root location:  web/crystalreportviewers
    The changes should always be in web.xml.
    1st: change the crystal_image_uri value to ../crystalreportviewers
    2nd: change crystal_image_use_relative value to "web"
    Change to "web" instead of webapp because that is what I named my web root folder.
    <context-param>
              <param-name>crystal_image_uri</param-name>
              <param-value>../crystalreportviewers</param-value>
         </context-param>
         <context-param>
              <param-name>crystal_image_use_relative</param-name>
              <param-value>web</param-value>
         </context-param>
    Thank you. You showed me the way on how to solve the 3 day problem.
    BTW, my next problem is when clicking on any buttons prev/next/print/export, I got this error HTTP Status 404.
    Well, at least for now I can view my initial report.  I just need to figure out the next issue and with the help of the great people here in the forum.
    Thanks a lot.
    Regards,
    Rulix
    Edited by: Rulix Batistil on Nov 26, 2008 7:27 AM

  • How to change images dynamically in jsp?

    Hi All,
    i Want to know how to change images dynamically in jsp, for example in any site if u look at advertise or any images, it will be changed after every few seconds.
    Please guide me
    Thanks
    Sandesh S

    sandeshas wrote:
    Hi BlusC,
    i was searching your mail Id to ask the question directly to u,i checked in your blog also, but i didnt get,I want to keep my email spam safe. Only trusted people and direct friends have it. Just use the forums for discussion.
    my question is suppose if i want to display and change the advertise(adds from different company ) in my web site,how can i do it by using jsp?
    Do i need to create animated gifs which contains all company adds??one might be from movie add,after few seconds next one migth be some other web site add like that, how can i achieve this in my servet,jsp or using struts.You create animated gifs with an [animated gif editor|http://google.com/search?q=animated+gif+editor]. There is nothing what JSP can do for you here.

  • Downloading image using servlet/jsp

    Has anyone tried downloading a .gif image using servlet/jsp ??!?

    Yes, there's even an example in my book about servlets.

  • Display Image in another jsp

    hello,
    I am facing a design issue of so as to how to go about displaying an image which i am retrieving from database.
    I have a SubmitDoc.jsp which takes as input the doc id which i need to display looks like :
    *SubmitDoc.jsp*
    <FORM METHOD=POST ACTION="Retrieval">
    Enter Document ID to Retrieve: <INPUT TYPE=TEXT NAME=DOCID SIZE=20/><BR>
    <P><INPUT TYPE=SUBMIT></P>
    </FORM>I have my Retrieval servlet which access the DB and gets the binary stream for the image data based on DOCID.
    Now i try to forward result to a different jsp in order to display the binary data from the servlet.
    something like this :
    InputStream readImg = rs.getBinaryStream("DOCUMENT");
    response.setContentType("image/jpg");
    request.setAttribute("ImageData", readImg);
    // response.getOutputStream().write(rb,0,len);
    RequestDispatcher rd = request.getRequestDispatcher("DisplayDoc.jsp");
    rd.forward( request, response );What code should i put in DisplayDoc.jsp to show the image there.
    Any ideas how do i go about ?
    Thanks,

    What code should i put in DisplayDoc.jsp to show the image there.The same code you put in any html page to show an image:
    <img src="urlToDownloadImageFrom"/>In effect you have two requests.
    One for the JSP page, and then another for the image.
    So often what you find is the tag on your page needs to pass the id as well
    <img src="/ImageServlet?docId=abc123"/>

  • Display BLOB Image in a JSP page.

    Hi, Is there any easy way to display a Image in the browser using a JSP and an Oracle BLOB. I would like any code examples that anyone can provide me. I would like as many ways to do this as possible.
    Thanks Brian

    You can do it in 2 ways:
    1. Get the BLOB from the DB and then write it into the local harddisk where the Web Server is located and then give the path in the <IMG SRC> Tag.
    2. In the JSP, when you specify a IMG Tag
    <IMG SRC='FileDisplayServlet?hdImgName=new.gif'>
    This SRC is pointing to a Servlet. The Servlet will read the Query String and then go hit the DB, get the BLOB Content and then convert into a byte array. Now the servlet will change its content type to image or gif. Then it will write the content in the out stream.
    Hope this helps.
    Thanks and regards,
    Pazhanikanthan. P

  • Proble displaying images dynamically in jsp

    Hi, I am new here. I have to display the images dynamically reading from a database. I have no problem displaying images. When i try to reduce the width in img tag then it is slowly rendering it. How to overcome this.
    <img src="image.jsp?imgID=112" width="150" heigth="130" border="0">
    I am also giving the sample jsp to display
         byte [] imgData = blob.getBytes(1,(int)blob.length());
    response.setContentType("image/jpeg");
    OutputStream o = response.getOutputStream();
    o.write(imgData);
    I want to display the image without any time taken. How could I solve this. Please Help me.
    Thanks.
    Phani.

    You should not crosspost questions. It is rude and a waste of our time.
    Please stick to one topic: [http://forums.sun.com/thread.jspa?threadID=5372144].

  • HOWTO: Display a custom image on a jsp page

    You need 4 files.
    1. a jsp page (index.jsp)
    2. A servlet (myPackage.ImageMaker)
    3. A supplier class (myPackage.PluggableSupplier)
    4. web.xml (your IDE should supply this)
    From the jsp page you're calling the servlet with an <img> tag, and passing it some parameters.
    The servlet obtains a BufferedImage from a pluggable supplier class, and returns with an image (png).
    The image is displayed on the jsp page. Hope this helps!
    ================================================================================================
    Here's the .jsp file (index.jsp)
    <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
    <html>
        <head>
            <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
            <title>Image page</title>
        </head>
        <body>
        <h1>Your image:</h1>
        <img src="ImageMaker?Param1=Hello world&Param2=Hello again" />
        </body>
    </html>================================================================================================
    Here's the servlet (ImageMaker.java):
    package myPackage;
    import java.awt.Color;
    import java.awt.Graphics;
    import java.awt.image.BufferedImage;
    import java.io.*;
    import javax.imageio.ImageIO;
    import javax.servlet.*;
    import javax.servlet.http.*;
    public class ImageMaker extends HttpServlet {
        protected void processRequest(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            System.out.println("called");
            //Prevent chacing of the image as it's probably intended to be 'dynamic'
            response.addDateHeader("Expires", 795294400000L); //<--long ago
            response.addHeader("Cache-Control", "no-store, no-cache, must-revalidate, post-check=0, pre-check=0");
            response.addHeader("Pragma", "no-cache");
            //set mime type and get output stream
            response.setContentType("image/png");
            OutputStream out = response.getOutputStream();
            //catch incoming parameters, as many or few as you want
            String parameter1 = request.getParameter("Param1");
            String parameter2 = request.getParameter("Param2");
            //fetch the buffered image
            int width = 100;
            int height = 50;
            PluggableSupplier ps = new PluggableSupplier(width, height);
            BufferedImage buf = ps.fetchBI(parameter1);
            /***You can now draw on the original image if you want to add a watermark or label or whatever*********/
            Graphics g = buf.getGraphics();
            g.setColor(Color.BLACK);
            g.drawString(parameter2, 5, 30);
            try {
                System.out.println("writing...");
                ImageIO.write(buf, "png", out);
            } catch(IOException ioe) {
                System.err.println("Error writing image file: " + ioe);
        protected void doGet(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
        protected void doPost(HttpServletRequest request, HttpServletResponse response)
        throws ServletException, IOException {
            processRequest(request, response);
    }================================================================================================
    This is the class that supplies your image (PluggableSupplier.java):
    package myPackage;
    import java.awt.Color;
    import java.awt.Graphics2D;
    import java.awt.image.BufferedImage;
    public class PluggableSupplier {
        BufferedImage buf = null;
        Graphics2D g2d = null;
        int width = 50;
        int height = 50;
        public PluggableSupplier(int w, int h) {
            if ((w+h)>2) {
                this.width = w;
                this.height = h;
            buf = new BufferedImage(width, height, BufferedImage.TYPE_INT_RGB);
            g2d = buf.createGraphics();
        public BufferedImage fetchBI(String parameter1) {
            if (g2d != null) {
                g2d.setColor(Color.RED);
                g2d.fillRect(0, 0, width, height);
                g2d.setColor(Color.WHITE);
                g2d.drawString(parameter1, 5, 15);
            return buf;
    }================================================================================================
    finally, your web.xml should look like this:
    <?xml version="1.0" encoding="UTF-8"?>
    <web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
        <servlet>
            <servlet-name>ImageMaker</servlet-name>
            <servlet-class>myPackage.ImageMaker</servlet-class>
        </servlet>
        <servlet-mapping>
            <servlet-name>ImageMaker</servlet-name>
            <url-pattern>/ImageMaker</url-pattern>
        </servlet-mapping>
        <session-config>
            <session-timeout>
                30
            </session-timeout>
        </session-config>
        <welcome-file-list>
         <welcome-file>
                index.jsp
            </welcome-file>
        </welcome-file-list>
    </web-app>null

    Another trick I learned (the hard way ;))...it's a good idea to buffer the output before responding. Add the following code to the servlet, in the case of the provided example, where all the other response-related stuff are done:
    response.setBufferSize(yourBufferSize);It's a good idea to try and calculate the buffer size as accurately as possible.

  • How can I get the resolution of an image file in JSP?

    how can I get the resolution of an image file like jpg,gif,png in JSP ?

    Hii,
    If by the resolution, u mean size..this is how u can come to know....
    String add = "path/to/some.jpeg";
    javax.swing.ImageIcon chain = new javax.swing.ImageIcon(add);
    int height = chain.getIconHeight();
    int width = chain.getIconWidth();
    Hope that helps.
    regards
                   

Maybe you are looking for

  • Help with MS Word, (Yes I have asked MS)

    I'm trying to solve a simple problem with Microsoft Word (2008 for Mac). I have tried on the Microsoft forums, they're useless. My problem sounds simple I cannot get my font size to "stick". I will change my font size to a 14.   As soon as I press th

  • Problem playing DVD with FrontRow

    Hi, watched my first DVD (regular DVD, no rip) with Front Row. Two problems: - There was an incredible delay when I tried to use the infrared remote during the movie. Turning down the volume took the imac about two minutes to process the request. - A

  • Port Replicator (45K1610), x301, and resolution help

    I have a x301, a port replicator with model number 45K1610, and a Dell 22" wide screen monitor.  When I connect the monitor directly to the laptop I can get the max resolution of 1680x1050 out of the monitor but when I plug the monitor through the po

  • Purchased tv show on my iPhone, how do i get it to play on my apple tv or computer

    I recently purchased tv show on my iPhone, how do i get it to play on my apple tv or computer?

  • Restriction of promotion attribute values

    Does anybody know how to restict the values of attributes for promotions. For example we want to enter a rabatt (save) for promotions and need the value for further calculations. How can I avoid the user enters 25 %, 25 or 0,25. Thanks in advance. Th