struts: problem getting images to show up

Posted on 2006-05-24
Last Modified: 2010-04-01
I am using struts with tiles.

all my images are in project/web/images/. in the html page I am using ./images/xyz.gif to refer to an image, this works fine was pages that are in web directory.

if my action forward path is /actions/customer then the image url becomes /actions/customer/images and hence is not able to find any of the images.

is there a easier way to deal with it. I am confused with paths.

Question by:muthiahmerchant
    LVL 4

    Accepted Solution

    Couple of ways.

    1 - use the struts html:img tag, which automatically adds in the servlet context part of the URL, and so will let you use absolute references
    <html:img page="/images/xyz.gif">

    2 - use the struts <html:base> tag on your page.
    A base tag tells a web page where to resolve relative links to.
    That means that you can use links relative to where your JSP is in the directory structure, rather than to the "action" you call it with.

    LVL 1

    Author Comment

    Thanks. <html:img>  worked very well.

    along the same lines can you help me figure out how to determine the path for my right now I have to use an absolute path.

    My app is in c:/myprojects/CAS but my tomcat is in C:\Program Files\netbeans-5.5beta\enterprise3\apache-tomcat-5.5.16

    hence when i use user.dir it takes me to C:\Program Files\netbeans-5.5beta\enterprise3\apache-tomcat-5.5.16 and not c:/myprojects/CAS.

    is there a way I can put my in c:/myprojects/cas/ and be able to use it without using absolut path.

    I will award the points for this question. even if you don't  konw the answer to

    Thanks a lot
    LVL 1

    Author Comment

    Sounds right. I will close this question


    Write Comment

    Please enter a first name

    Please enter a last name

    We will never share this with anyone.

    Featured Post

    6 Surprising Benefits of Threat Intelligence

    All sorts of threat intelligence is available on the web. Intelligence you can learn from, and use to anticipate and prepare for future attacks.

    Suggested Solutions

    Title # Comments Views Activity
    String format issue 13 86
    java cigar challenge 58 199
    dateFashion java challenge 9 121
    Handle form fields in spring mvc controller 1 50
    Outlook Free & Paid Tools
    This paper addresses the security of Sennheiser DECT Contact Center and Office (CC&O) headsets. It describes the DECT security chain comprised of “Pairing”, “Per Call Authentication” and “Encryption”, which are all part of the standard DECT protocol.
    To add imagery to an HTML email signature, you have two options available to you. You can either add a logo/image by embedding it directly into the signature or hosting it externally and linking to it. The vast majority of email clients display l…
    In this sixth video of the Xpdf series, we discuss and demonstrate the PDFtoPNG utility, which converts a multi-page PDF file to separate color, grayscale, or monochrome PNG files, creating one PNG file for each page in the PDF. It does this via a c…

    758 members asked questions and received personalized solutions in the past 7 days.

    Join the community of 500,000 technology professionals and ask your questions.

    Join & Ask a Question

    Need Help in Real-Time?

    Connect with top rated Experts

    10 Experts available now in Live!

    Get 1:1 Help Now