Not able to link CSS and images

后端 未结 2 1840
青春惊慌失措
青春惊慌失措 2021-01-23 19:01

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

相关标签:
2条回答
  • 2021-01-23 19:17

    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" />

    0 讨论(0)
  • 2021-01-23 19:27

    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" %>
    
    0 讨论(0)
提交回复
热议问题