Reputation: 3398
I'm new to spring mvc, I have successfully setup a welcome page but the image that I have added in it not displaying, after reading lots of articles I have managed to modify my spring-dispatcher-servlet.xml like below
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:aop="http://www.springframework.org/schema/aop"
xmlns:context="http://www.springframework.org/schema/context"
xmlns:jee="http://www.springframework.org/schema/jee"
xmlns:tx="http://www.springframework.org/schema/tx"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xmlns:mvc="http://www.springframework.org/schema/mvc"
xsi:schemaLocation="http://www.springframework.org/schema/aop
http://www.springframework.org/schema/aop/spring-aop-2.5.xsd
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans-2.5.xsd
http://www.springframework.org/schema/context
http://www.springframework.org/schema/context/spring-context-2.5.xsd
http://www.springframework.org/schema/jee
http://www.springframework.org/schema/jee/spring-jee-2.5.xsd
http://www.springframework.org/schema/tx
http://www.springframework.org/schema/tx/spring-tx-2.5.xsd
http://www.springframework.org/schema/mvc
http://www.springframework.org/schema/mvc/spring-mvc-3.0.xsd">
<context:component-scan base-package="com.diluks.controller" />
<bean id="viewResolver"
class="org.springframework.web.servlet.view.InternalResourceViewResolver" >
<property name="prefix">
<value>/WEB-INF/</value>
</property>
<property name="suffix">
<value>.jsp</value>
</property>
</bean>
<mvc:resources mapping="/resources/**" location="/resources/" />
<mvc:annotation-driven />
</beans>
and my index.jsp page is like below
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>My Page Title</title>
</head>
<body>
<h1>${welcomemessage}</h1>
<img alt="Image" src="/resources/images/testimage.jpg">
</body>
</html>
It gives me the Welcome Message correctly but it does not display the image. Please help me on this.
Upvotes: 1
Views: 3016
Reputation: 2100
If your using JSTL, try
<img alt="Image" src="<c:url value="/resources/images/testimage.jpg"/>"/>
If you are not using, then you can try
<img alt="Image" src="${pageContext.request.contextPath}/resources/images/testimage.jpg"/>
Upvotes: 2
Reputation: 6089
Change image src attributes value to following :
<img alt="Image" src="${pageContext.request.contextPath}/resources/images/testimage.jpg">
Give this a try.
Upvotes: 2