这是我的spring mvc项目,在这里我要提到此Java类中的配置。

MVCConfiguration.java

 @Configuration
    @ComponentScan(basePackages="com.java.spring")
    @EnableWebMvc
    public class MvcConfiguration extends WebMvcConfigurerAdapter{

        @Bean
        public ViewResolver getViewResolver(){
            InternalResourceViewResolver resolver = new InternalResourceViewResolver();
            resolver.setPrefix("/WEB-INF/views/");
            resolver.setSuffix(".jsp");
            return resolver;
        }

        @Override
        public void addResourceHandlers(ResourceHandlerRegistry registry) {
            registry.addResourceHandler("/resources/**").addResourceLocations("/resources/");
        }



}


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"
    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_3_0.xsd"
    id="WebApp_ID" version="3.0">
    <display-name>SpringMvcFormExample</display-name>
    <context-param>
        <param-name>contextClass</param-name>
        <param-value>
            org.springframework.web.context.support.AnnotationConfigWebApplicationContext
        </param-value>
    </context-param>
    <listener>
        <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
    </listener>

    <servlet>
        <servlet-name>SpringDispatcher</servlet-name>
        <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
        <init-param>
            <param-name>contextClass</param-name>
            <param-value>
                org.springframework.web.context.support.AnnotationConfigWebApplicationContext
            </param-value>
        </init-param>
        <init-param>
            <param-name>contextConfigLocation</param-name>
            <param-value>com.java.spring</param-value>
        </init-param>
        <load-on-startup>1</load-on-startup>
    </servlet>
    <servlet-mapping>
        <servlet-name>SpringDispatcher</servlet-name>
        <url-pattern>/</url-pattern>
    </servlet-mapping>

    <session-config>
        <session-timeout>30</session-timeout>
    </session-config>
</web-app>


webapp / resources / style.css

html,body,div,span,
applet,object,iframe,code,
h1,h2,h3,h4,h5,h6,p,blockquote,pre,
a,abbr,acronym,address,big,cite,
del,dfn,font,img,ins,kbd,q,s,samp,
small,strike,sub,sup,tt,var,
dd,dl,dt,li,ol,ul,
fieldset,form,label,legend,
table,caption,tbody,tfoot,thead,tr,th,td {
    margin: 0;
    padding: 0;
    border: 0;
    font-weight: normal;
    font-style: normal;
    font-family: inherit;
    text-align: left;
}
table {
    border-collapse: collapse;
    border-spacing: 0;
}
ul {
    list-style: none;
}
q:before,q:after,
blockquote:before,blockquote:after {
    content: "";
}

#header{
    background-color:#2B477D;
    width:1600000px;
    float:left;
}

h1 {
    color: #fff;
    text-align: center;
    padding: 80px 0 30px 0;
}

h2 {
    text-align: center;
    padding: 40px 0 0 0;
    width: 75%;
    margin: 0 auto;
}

body {
    background: #CBD4E5;
}

ol {
    list-style: decimal;
    font-size: 24px;
    width: 400px;
    padding: 30px 0 0 60px;
    margin: 0 auto;
}

ul#navigation {
    height: 36px;
    padding: 20px 0px 0 0px;
    width: 900px;
    margin: 0 auto;
    position: relative;
    overflow: hidden;
}


webapp / WEB_INF / views / AddModifyCustomer.jsp

<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
<title>Manage Customer</title>

<link rel="stylesheet" href="resources/styles.css" type="text/css" media="screen" />

<script type="text/javascript" src="http://ajax.googleapis.com/ajax/libs/jquery/1.2.6/jquery.min.js"></script>

</head>


请建议我我要去哪里错了?

最佳答案

尝试

<link rel="stylesheet" type="text/css" href="${pageContext.servletContext.contextPath}/resources/tyles.css">

10-08 19:10