Access image from Resources spring

Asked

Viewed 545 times

0

I have the following scenario:

inserir a descrição da imagem aqui I have the srping-Servlet.xml file with the following configuration:

<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-4.0.xsd
 	http://www.springframework.org/schema/mvc
 	http://www.springframework.org/schema/mvc/spring-mvc-4.0.xsd
 	http://www.springframework.org/schema/context
 	http://www.springframework.org/schema/context/spring-context-4.0.xsd">

	<context:component-scan base-package="com.websystique.springmvc.controller" />

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

	
	<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 the Hello World method that I want to show the image for example logo_vallon.jpg and I am using the following code in the Helloworldcontroller class.java:

@RequestMapping(method = RequestMethod.GET)
	public String sayHello(ModelMap model) {
		model.addAttribute("greeting", "<img src=\"/resources/images/logo_vallon.jpg\"/>Hello World from Spring 4 MVC");
		return "welcome";
	}

but when I run the code it looks like this:

inserir a descrição da imagem aqui

when I send the page information is like this:

<!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>HelloWorld page</title>
</head>
<body>
	Greeting : <img src="/resources/images/logo_vallon.jpg"/>Hello World from Spring 4 MVC
</body>
</html>

and the jsp file is being created that way:

<%@ 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>HelloWorld page</title>
</head>
<body>
	Greeting : ${greeting}
</body>
</html>

I’m already over 3 days trying to make the image appear unsuccessfully, can someone give me a light for this please? can you tell me where the error is?

1 answer

1

After many hours, follow the answer:

<img src="images/logo_vallon.jpg"/>

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

Browser other questions tagged

You are not signed in. Login or sign up in order to post.