0

I am using Maven project and I am trying to display Image, Below is my code for header part,

<div>
        <div id="header-top">
                <ul class="lang-nav">
                    <li><a  id="active" href="" title="en">EN</a></li>
                    <li><a href="" title="fr">FR</a></li>
                    <li><a href="" title="nl">NL</a></li>
                </ul>
        </div>
        <div id="header-bottom">
            <img src="/resources/images/Mobistar.jpg" />
        </div>
    </div>

servlet-context.xml

<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:context="http://www.springframework.org/schema/context" 
xmlns:mvc="http://www.springframework.org/schema/mvc" 
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">

    <context:component-scan base-package="com.mobistar.eidsar.controller" />
    <context:property-placeholder location="classpath:validation.properties"/>
    <mvc:annotation-driven />
    <mvc:resources mapping="/resources/**" location="/resources/" />

    <bean id="messageSource"
        class="org.springframework.context.support.ResourceBundleMessageSource">
        <property name="basename" value="validation" />
    </bean>

    <bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/views/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>
</beans>    

I have my images path in /eidsar/src/main/webapp/resources/images/Mobistar.png and my jsp in /eidsar/src/main/webapp/WEB-INF/views/header.jsp, I am not able to see the image. Any help would be highly appreciated. Dont mark this as duplicate as I havenot found any solution yet.

Subodh Joshi
  • 12,717
  • 29
  • 108
  • 202
Thej
  • 191
  • 1
  • 6
  • 23
  • see in your browser's console :the path used for the image. Now match that path in your war file. – Pallav Jha Mar 07 '16 at 05:04
  • This link helped me to get the solution, http://stackoverflow.com/questions/20369529/how-to-display-image-in-jsp-with-spring-mvc Thanks! – Thej Mar 07 '16 at 05:51

1 Answers1

0
Use the context path like this:
<div id="header-bottom">
 <img src="<%=request.getContextPath()%>/resources/images/Mobistar.jpg" />
</div>
muthu
  • 16
  • 2