Announcement Announcement Module
Collapse
No announcement yet.
img tag problem Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • img tag problem

    I have a problem with img tag within my page. I can't see any images in browser

    This is my img tag
    HTML Code:
    <img src="images/login_button.gif">
    and this is images directory:
    webapp
    WEB-INF
    images
    login_button.gif

    this is my only spring handler mapping I have

    HTML Code:
    <bean class="org.springframework.web.servlet.handler.SimpleUrlHandlerMapping">
    	<property name="mappings">
    		<props>
    			<prop key="/login.html">loginController</prop>
    			<prop key="/index.html">indexController</prop>
    		</props>
    	</property>	
    	</bean>
    web.xml
    HTML Code:
     <web-app>
     	<display-name>Aplikacja</display-name>
     	<context-param>
     		<param-name>contextConfigLocation</param-name>
     		<param-value>/WEB-INF/spring-context.xml</param-value>
     	</context-param>
     	
     	<listener>
     		<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
     	</listener>
     	
     	<servlet>
     		<servlet-name>appServlet</servlet-name>
     		<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
     	</servlet>
     	
     	<servlet-mapping>
     		<servlet-name>appServlet</servlet-name>
     		<url-pattern>*.html</url-pattern>
     	</servlet-mapping> 	
     </web-app>

  • #2
    You have the images folder within the WEB-INF folder, which means it won't be visible to a browser. You need to move it to the web app's root directory (i.e., alongside the WEB-INF folder, not within it). This will obviously have to be reflected in the URLs you use. I find it best to use the c:url tag from JSTL, which takes care of the context for you:

    <img src="<c:url value='/images/login_button.gif'/>">

    Note the leading slash before images - this makes the context relative to the web application.

    Comment

    Working...
    X