我无法将css文件链接到我的项目

时间:2015-01-30 11:36:45

标签: java html css xml spring

现在我使用Spring Framework处理web项目java。我遇到了一件非常奇怪的事情,我无法靠自己决定。 我在web.xml中使用了这样的servlet -mapping:

<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd" id="WebApp_ID" version="2.5">
    <context-param>
        <param-name>contextConfigLocation</param-name>
        <param-value>/WEB-INF/applicationContext.xml</param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>
    <servlet>
        <servlet-name>dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <load-on-startup>2</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>
</web-app>

如果我将servlet-mapping中的url-pattern更改为* .htm,则我的css已成功链接。但是使用这种模式,我无法进行分页,因此我无法接受此类型。

我已尝试过将css链接起来的方式:

<c:set var="root" value="${pageContext.request.contextPath}" />
<link href="${root}/css/bootstrap.css" rel="stylesheet">`
<link href="<c:url value="/css/bootstrap.css"/>" rel="stylesheet" type="text/css">

请帮帮我!我的大脑会爆炸)

1 个答案:

答案 0 :(得分:0)

问题在于不安定的url模式。允许web.xml

中的资源
<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>/css/*</url-pattern>
</servlet-mapping>