Announcement Announcement Module
Collapse
No announcement yet.
I can not display image in jsp page? Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • I can not display image in jsp page?

    I use NetBeans 6.7.1 to do with Spring. In my index.jsp, I use <img to display image. But when I run it, this image don't display.

    <img alt="Muziic Logo" src="header_logo.jpg" />

    index.jsp and header_logo.jsp are in a folder.

    Anyone can help me, please!

    Thank you very much!

  • #2
    Can you tell me where you kept your index.jsp and where you kept your image file?
    According to your code, the image file must be kept in same location with your index.jsp pages.

    Comment


    • #3
      Originally posted by romeshnongthombam View Post
      Can you tell me where you kept your index.jsp and where you kept your image file?
      According to your code, the image file must be kept in same location with your index.jsp pages.
      This is my project structure.
      http://www.mypicx.com/thumb/123467612_11012009_1.jpg

      Comment


      • #4
        Files inside the WEB-INF cannot be accessed by the browser directly.

        You cannot kept the css and img folders inside the WEB-INF folder.

        Copy your css and img folder in root folder ( "Web Pages/" folder not inside "Web Pages/WEB-INF" folder)

        So your css folder path will be "Web Pages/css"
        Img folder - "Web Pages/img"

        Then you can put the header_logo.jpg inside "Web Pages/img" folder

        <img src='/img/header_logo.jpg' alt='title' />

        Comment


        • #5
          Originally posted by romeshnongthombam View Post
          Files inside the WEB-INF cannot be accessed by the browser directly.

          You cannot kept the css and img folders inside the WEB-INF folder.

          Copy your css and img folder in root folder ( "Web Pages/" folder not inside "Web Pages/WEB-INF" folder)

          So your css folder path will be "Web Pages/css"
          Img folder - "Web Pages/img"

          Then you can put the header_logo.jpg inside "Web Pages/img" folder

          <img src='/img/header_logo.jpg' alt='title' />
          I copied img and css folder in Web Pages/ folder. But the image dosen't display. index.jsp is in Web Pages/WEB-INF/jsp . So I think, src='/img/header_logo.jpg' is wrong.
          Can you give me a solution?
          Thank you?

          Comment


          • #6
            Yes,index.jsp is inside WEB-INF/jsp folder. In your spring you have configured like this. There is no problem when keeping the image outside WEB-INF and JSP inside WEB-INF/jsp folder.


            So, how you access your index.jsp?
            Like this http://localhost/Web Pages/index.htm or http://localhost/Web Pages/index.jsp

            src='/img/header_logo.jpg' . The "/" in the src indicates the root folder, that means its saying the img folder must be in Web Pages folder.

            Try this if it does not work <img src='img/header_logo.jpg' alt='title' />

            In the browser,type "http://localhost/Web Pages/img/header_logo.jpg" If you see the images, then you place the image in correct path

            It is not recommend to have space in the web application name "Web Pages",try renaming "webpages" or "Web_pages".

            Comment


            • #7
              I use Netbeans IDE 6.7.1, it auto set jsp file inside WEB-INF/jsp folder.
              And dispatcher-servlet.xml configure to this location.

              <bean id="viewResolver"
              class="org.springframework.web.servlet.view.Intern alResourceViewResolver"
              prefix="/WEB-INF/jsp/"
              p:suffix=".jsp" />

              I copied index.jsp to root folder. And the image displayed good.
              But I want that, while index.jsp is in WEB-INF/jsp folder, the image also display good!

              Thank you for your help!

              Comment

              Working...
              X