I am working on a Spring, Hibernate, JSP application. I am trying to display an image from my JSP page. The image not displayed on the browser. I am also not able to link my CSS
I have resolved the issue by adding following mapping in web.xml
file
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.js</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.gif</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.jpg</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.png</url-pattern>
</servlet-mapping>
and also by adding <%=request.getContextPath()%>
in image src url.
Like <img src="<%=request.getContextPath()%>/images/logo.png" />
You could use JSTL <link href="<c:url value='/css/style.css'/>"
tag for this the same shoult do for images. <img src="<c:url value='/images/Logo1.png'/>"
.
You also need to add to the page
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>