How to display images in a jsp file in Spring MVC

Abdul picture Abdul · Sep 29, 2015 · Viewed 8.7k times · Source

I am very new to spring. I am using spring 3.29 version, tomcat 7. I need to display an image in .jsp file. I searched a lot. There are plenty of post about this problem. But still i am unable to solve this problem. Please help.

The following is my application structure

The following is my application structure

The following is my spring-servlet.xml file code

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:p="http://www.springframework.org/schema/p"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="http://www.springframework.org/schema/beans  
        http://www.springframework.org/schema/beans/spring-beans-3.2.xsd  
        http://www.springframework.org/schema/context  
        http://www.springframework.org/schema/context/spring-context-3.2.xsd
        http://www.springframework.org/schema/mvc 
    http://www.springframework.org/schema/mvc/spring-mvc-3.2.xsd">

    <context:component-scan base-package="com.wipro.controller" />
    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.UrlBasedViewResolver">
        <property name="viewClass">
            <value>
                org.springframework.web.servlet.view.tiles2.TilesView
            </value>
        </property>
    </bean>
    <bean id="tilesConfigurer"
        class="org.springframework.web.servlet.view.tiles2.TilesConfigurer">
        <property name="definitions">
            <list>
                <value>/WEB-INF/tiles.xml</value>
            </list>
        </property>
    </bean>
</beans>

I have a page footer.jsp. I need to add an image in this file The following is code

<!-- Here I need to add an image -->
<hr/>  
<p>Copyright  2010-2014 javatpoint.com.</p>  

Answer

Abdul picture Abdul · Sep 29, 2015

I got the image in my page. @Pankaj Saboo comments helped a lot. Thanks for all of you.

I have added the below code in spring-servlet.xml

<mvc:annotation-driven />
<mvc:resources mapping="/images/**" location="WEB-INF/resources/images/" />

And in footer.jsp I have added the below code

<img src="<c:url value="/images/wipLogo.png" />"/>