4 Replies Latest reply on Sep 16, 2003 9:53 AM by just_a_w

    Images only display with certain context

    just_a_w Newbie

      I am deploying a servlet that prints an html pages with some images. But the images don't display.

      EAR file layout:
      application.xml
      Chat.war

      Within Chat.war:
      images/pic.jpg
      WEB-INF/lib/log4j.jar
      WEB-INF/classes/Controller.class
      WEB-INF/jboss-web.xml
      WEB-INF/web.xml

      In the html, I am using the following to try to display an image:


      In the web.xml:

      <servlet-mapping>
      <servlet-name>Controller</servlet-name>
      <url-pattern>/</url-pattern>
      </servlet-mapping>


      But the image doesn't display. Any idea why?

      Thanks...


        • 1. Re: Images only display with certain context
          just_a_w Newbie

          If I change the servlet-mapping to specify a url-pattern other than "/", I can go to that page and the image will display.

          So if I have the following, I can go to http://:8080/something and I will see the image.

          <servlet-mapping>
             <servlet-name>Controller</servlet-name>
             <url-pattern>/something</url-pattern>
          </servlet-mapping>

          But if someone navigates to the root context at http://:8080/  they see a listing of the contents of my war file.

          Any suggestions?

          • 2. Re: Images only display with certain context
            Jon Barnett Master

            The URL pattern is to map whatever matches the pattern you specify to the servlet named Controller. Placing just a '/' for the mapping is probably not the outcome you want. Please read a servlet tutorial or get a servlet development book to work through the web.xml deployment definitions.

            The default application context for your WAR is Chat, assuming that your application.xml does not have an override for this mapping. This means that the overall URL for accessing your image locally would be:
            http://localhost:8080/Chat/images/pic.jpg. Note that this is within your default application context /Chat.

            From your description, you appear to be overriding the default application context, moving your application to the root context. So I am assuming this is what your are doing.

            With the pattern match '/something', it means that your Controller servlet is run when you access http://localhost:8080/something.

            Normally a web application expects an index.html, index.htm or index.jsp to be found when you enter just the http://localhost:8080/. Otherwise, with the default settings, you will get a directory listing. The configuration for welcome files <welcome-file-list> will be explained in a good servlet tutorial. This is probably a better method for achieving what you want.

            • 3. Re: Images only display with certain context
              Raja Master

              If u make ur application.xml map ur WAR To /, you should be able to achieve what you are trying to do.

              Also, if u dont want the listings to be shown(on Tomcat), turn the "listings" tag to false in the <JBoss_Dist>/catalina/conf/web.xml

              -Raj

              • 4. Re: Images only display with certain context
                just_a_w Newbie

                Thanks for the responses!

                One thing I forgot to mention is that I've set the context root in jboss-web.xml as follows:

                <context-root>/</context-root>

                Right now I'm only planning to deploy a single app on my server. So when people to navigate to my server, I want my app to be displayed at http://, without a uri on the end (without /Chat or anything).