如何在spring MVC中的jsp文件中显示Image

时间:2016-03-07 03:46:09

标签: spring jsp spring-mvc

我正在使用Maven项目,我正在尝试显示Image,下面是我的标题部分代码,

<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>    

我在/eidsar/src/main/webapp/resources/images/Mobistar.png中有我的图片路径,我的jsp在/eidsar/src/main/webapp/WEB-INF/views/header.jsp,我是无法看到图像。任何帮助将受到高度赞赏。不要将此标记为重复,因为我还没有找到任何解决方案。

1 个答案:

答案 0 :(得分:0)

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