无法在spring mvc的jsp中加载图像文件而无法获取图像的替代文本

时间:2014-09-09 12:02:39

标签: java spring jsp spring-mvc

我无法在我的spring mvc应用程序的jsp中加载图像文件。我的目录结构和代码就像是休闲......我甚至无法获得图像的替代文本..请帮帮我..

servlet的context.xml中

<context:component-scan base-package="com.imr.smsapp.web"/>
<context:property-placeholder location="classpath:database.properties"/>
<mvc:annotation-driven/>
<mvc:default-servlet-handler />
<mvc:resources  mapping="/resources/**" location="/resources/images/,/resources/css/,/resources/pages/"/>

<bean id="dataSource" class="org.springframework.jdbc.datasource.DriverManagerDataSource">
<property name="driverClassName" value="${jdbc.driverClassName}"/>
<property name="url" value="${jdbc.url}"/>
<property name="username" value="${jdbc.username}"/>
<property name="password" value="${jdbc.password}"/>
</bean>
<bean id="sessionFactory" class="org.springframework.orm.hibernate4.LocalSessionFactoryBean">
<property name="dataSource" ref="dataSource"/>
<property name="mappingResources">
<list>
<value>com/imr/smsapp/model/Address.hbm.xml</value>
<value>com/imr/smsapp/model/Student.hbm.xml</value>
</list>
</property>
<property name="hibernateProperties">
<props>
<prop key="hibernate.dialect">${hibernate.dialect}</prop>
<prop key="hibernate.hbm2ddl.auto">${hibernate.hbm2ddl}</prop>
<prop key="hibernate.show_sql">${hibernate.show_sql}</prop>
</props>
</property>
</bean>
<bean id="txManager" class="org.springframework.orm.hibernate4.HibernateTransactionManager">
<property name="sessionFactory" ref="sessionFactory"/>
</bean>
<bean id="persistenceExceptionTranslationPostProcessor" 
class="org.springframework.dao.annotation.PersistenceExceptionTranslationPostProcessor"/>
<bean class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="prefix">
<value>/WEB-INF/views/student/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<bean id="studentDaoImpl" class="com.imr.smsapp.dao.Impl.StudentDaoImpl"/>
<bean id="studentServiceImpl" class="com.imr.smsapp.service.Impl.StudentServiceImpl"/>
</beans>

在form.jsp

</form:form>
<img  src="<c:url value="/resources/imgaes/random_number.png"/>" alt="Image alternate Text">
</body>

如果我在jsp的上面代码中使用src =“/ resources / imgaes / random_number.png”,我可以在jsp编辑器预览中看到图像,但在运行我的应用程序时却没有显示..

图片处于循环路径webroot / resources / images /...

1 个答案:

答案 0 :(得分:0)

此问题已修复。我将图片代码修改为

<img  src="${pageContext.request.contextPath}/resources/images/random_number.png" alt="Image alternate Text">

任何人都可以解释为什么以前的方法对我没有用的原因..