Show image in JSP

2

I'm having trouble displaying an image on my JSP page. I'm trying to use several different ways to get the file and I can not show it on the page.

The folders are arranged as follows

WebContent
|_1.jpg
|_ParaEmpresas.png
|_img
    |_1.jpg
    |_ParaEmpresas.png

The code in my jsp page

<img src="../../1.jpg"/>
<img src="<c:url value="/img/ParaEmpresas.png"/>" />
<img src="<c:url value="/ParaEmpresas.png"/>" />

and the error trying to load the page

ADVERTÊNCIA: No mapping found for HTTP request with URI [/DataIdea/img/1.jpg] in DispatcherServlet with name 'springmvc'set 08, 2015 4:13:08 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound

WEB.XML

<?xml version="1.0" encoding="UTF-8"?>

link

<welcome-file-list>
    <welcome-file>index.html</welcome-file>
    <welcome-file>index.htm</welcome-file>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>default.html</welcome-file>
    <welcome-file>default.htm</welcome-file>
    <welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<resource-ref>
        <description>postgreSQL Datasource example</description>
         <res-ref-name>jdbc/postgres</res-ref-name>
        <res-type>javax.sql.DataSource</res-type>
         <res-auth>Container</res-auth>
    </resource-ref>
<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>
        org.springframework.web.servlet.DispatcherServlet
    </servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>
            /WEB-INF/spring-context.xml
        </param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>

</servlet>

<session-config>
    <session-timeout>30</session-timeout>
</session-config>
<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>

</servlet-mapping>
<error-page>
    <exception-type>java.lang.Exception</exception-type>
    <location>/WEB-INF/views/erro/erro.jsp</location>
</error-page>
<listener>
    <listener-class>br.com.quartz.ListenToMeFirst</listener-class>
</listener>

    
asked by anonymous 17.06.2015 / 22:48

1 answer

1

One solution I found was to add this code in WEB.xml

    <servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>*.png</url-pattern>
    <url-pattern>*.jpg</url-pattern>
</servlet-mapping>

and reference the image using the following tag

<img src="<c:url value="….. "/>" />

Using this hierarchy in folders

WebContent
|_img
    |_ParaEmpresas.png

The code would look like this

 <img src="<c:url value="/img/ParaEmpresas.png"/>" />
    
09.09.2015 / 16:06