css -/resources/style.css 未在我的 spring 应用程序的 jsp 中获取

标签 css jsp spring-mvc

这是我的 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">

关于css -/resources/style.css 未在我的 spring 应用程序的 jsp 中获取,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25733434/

相关文章:

java - 根据TLD标签测试必须为空

java - 频繁发送到spring-websocket session : lost in transit

javascript - 如何将第二个模态定位在第一个模态之上?

html - Bootstrap 内联表单,带有 2 个输入,它们之间的填充较少

php - 发送 session 数据 : Php on one server and jsp on another

java - 如何在jsp/servlet中设置密码到期日期?

java - Spring MVC - 仅允许来自本地主机的请求到特定 Controller

spring-mvc - 没有可用于当前线程的实际事务的 EntityManager - 无法可靠地处理 'persist' 调用

c# - 仅使用 CSS 更改 ASP DropDownList 的背景颜色

html - 成为网页设计师 : CMS, 或手工