Reputation: 401
I have tried all combinations to display image in my jsp. But still image is not displaying.
I'm attaching Screenshot for the same.
In server Im getting this error
**[![Jun 21, 2016 11:16:40 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI \[/guestbook-webapp/images/Alarm_Tick_Icon_32.png\] in DispatcherServlet with name 'mvc-dispatcher'
Jun 21, 2016 11:22:15 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI \[/guestbook-webapp/images/Alarm_Tick_Icon_32.png\] in DispatcherServlet with name 'mvc-dispatcher'
Jun 21, 2016 11:22:15 PM org.springframework.web.servlet.DispatcherServlet noHandlerFound
WARNING: No mapping found for HTTP request with URI \[/guestbook-webapp/src/images/Alarm_Tick_Icon_32.png\] in DispatcherServlet with name 'mvc-dispatcher'][1]][1]**
Upvotes: 1
Views: 1812
Reputation:
Spring MVC handles resources differently with simple configuration requirement in spring-dispatcher.xml
file.
<mvc:resources mapping="/resources/**" location="/resources/" cache-period="31556926"/>
In your case, I think your Spring MVC XML file is in spring-config
folder, and you need to configure the MVC resource tag exactly this way:
<mvc:resources mapping="/images/**" location="/images/" cache-period="31556926"/>
And, have your JSP file include the JSTL library on top of the page and then fetch the image as shown below:
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
...
<img src="<c:url value="/images/Alarm_Tick_Icon_32.png"/>"/>
This was tested on my local server and proven to be successful. Please let us know whether this approach works out on your end, or you need more examples from web.xml
or spring-dispatcher.xml
files.
Upvotes: 1