我试图通过更改AdmissionForm.jsp文件中h3标记的内容来为某些主题的主页提供支持,但是单击红色或绿色链接后,我遇到了以下警告:

No mapping found for HTTP request with URI [/FirstSpringMVCProject/stylegreen.css] in DispatcherServlet with name 'spring-dispatcher'
or
No mapping found for HTTP request with URI [/FirstSpringMVCProject/stylered.css] in DispatcherServlet with name 'spring-dispatcher'


AdmissionForm.jsp文件中的一些代码

<%@taglib prefix="form" uri="http://www.springframework.org/tags/form" %>
<%@taglib prefix="spring" uri="http://www.springframework.org/tags" %>
<html>
<body>
<a href="/FirstSpringMVCProject/admissionForm.html?sitelanguage=en"> English </a> |
<a href="/FirstSpringMVCProject/admissionForm.html?sitelanguage=de"> German </a>

    <!--Added tut 27 for differnt themes -->
    <link rel="stylesheet" href="<spring:theme code='styleSheet'/>" type="text/css" />

    <p> <a href="/FirstSpringMVCProject/admissionForm.html?siteTheme=green">Green</a> |
        <a href="/FirstSpringMVCProject/admissionForm.html?siteTheme=red">Red</a> </p>

    <h1><spring:message code="label.headerMessage" /></h1>

    <h3> <spring:message code="label.admissionForm" /></h3>

</body>
</html>


spring-dispatcher-servlet.xml

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

<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:context="http://www.springframework.org/schema/context"
    xmlns:mvc="http://www.springframework.org/schema/mvc"

    xsi:schemaLocation="http://www.springframework.org/schema/beans
    http://www.springframework.org/schema/beans/spring-beans-3.0.xsd
    http://www.springframework.org/schema/context
    http://www.springframework.org/schema/context/spring-context-3.0.xsd
    http://www.springframework.org/schema/mvc
    http://www.springframework.org/schema/mvc/spring-mvc.xsd">


    <context:component-scan base-package="com.stack" />
    <mvc:annotation-driven />

    <!-- Added -->
    <mvc:interceptors>

        <bean class="org.springframework.web.servlet.i18n.LocaleChangeInterceptor">
            <property name="paramName" value="sitelanguage" />
        </bean>

        <!--Added tut 27 for diffent themes -->
        <bean class="org.springframework.web.servlet.theme.ThemeChangeInterceptor">
            <property name="paramName" value="siteTheme" />
        </bean>

    </mvc:interceptors>


    <bean id="viewResolver"
        class="org.springframework.web.servlet.view.InternalResourceViewResolver">
        <property name="prefix">
            <value>/WEB-INF/</value>
        </property>
        <property name="suffix">
            <value>.jsp</value>
        </property>
    </bean>

    <bean id="messageSource"
        class="org.springframework.context.support.ReloadableResourceBundleMessageSource">
        <property name="basename" value="/WEB-INF/studentmessages" />
        <property name="cacheSeconds" value="1" />
    </bean>

    <bean id="localeResolver"
        class="org.springframework.web.servlet.i18n.CookieLocaleResolver">
        <property name="defaultLocale" value="de_DE" />
        <!-- <property name="cookieName" value="idiomaCookie" /> <property name="cookieMaxAge"
            value="3600" /> -->
    </bean>

    <!--Added tut 27 for diffent themes -->
    <bean id="themeSource"          class="org.springframework.ui.context.support.ResourceBundleThemeSource">
        <property name="basenamePrefix" value="theme" />
    </bean>

    <bean id="themeResolver"
        class="org.springframework.web.servlet.theme.CookieThemeResolver">
        <property name="defaultThemeName" value="green" />
    </bean>


</beans>


theme-green.properties

styleSheet=./stylegreen.css


theme-red.properties

styleSheet=./stylered.css


风格绿色

H3{
    color: green; fornt-family: sams-serif; font-size: 20pt;
}


风格化

H3{
    color: red; fornt-family: arial; font-size: 20pt;
}


web.xml

<?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"
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>FirstSpringMVCProject</display-name>

    <servlet>
        <servlet-name>spring-dispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>

        <!-- value >= 0 means that the servlet is loaded when the web-app is deployed  -->
        <load-on-startup>1</load-on-startup>

    </servlet>

    <servlet-mapping>
        <servlet-name>spring-dispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>


</web-app>


java - 在名称为“spring-dispatcher”的DispatcherServlet中,未找到带有URI [/FirstSpringMVCProject/stylegreen.css]的HTTP请求的映射-LMLPHP

java - 在名称为“spring-dispatcher”的DispatcherServlet中,未找到带有URI [/FirstSpringMVCProject/stylegreen.css]的HTTP请求的映射-LMLPHP

最佳答案

资源不应存在于WEB-INF下,因为servlet容器绝不能直接从那里提供任何服务。当您将调度程序servlet映射到/而不是/*时,tomcat可以直接为WEB-INF之外的资源提供服务。

只需将CSS文件直接在WebContent下向上移动一个级别。

09-30 22:45
查看更多