为了将css引入jsp中,今天可真是踩了好多坑,最后在stackoverflow上找到了解决方法,不多说贴出代码。

在web.xml中添加以下代码:

<servlet-mapping>
<servlet-name>default</servlet-name>
<url-pattern>*.css</url-pattern>
</servlet-mapping>

spring-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:p="http://www.springframework.org/schema/p"
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 "> <mvc:annotation-driven />
<mvc:default-servlet-handler /> <mvc:resources mapping="/resources/**" location="/resources/css/"
cache-period="31556926"/> <!-- 扫描web包,应用Spring的注解 -->
<context:component-scan base-package="main.com.winjay.blog.web"/> <!-- 配置视图解析器,将ModelAndView及字符串解析为具体的页面 -->
<bean
class="org.springframework.web.servlet.view.InternalResourceViewResolver"
p:viewClass="org.springframework.web.servlet.view.JstlView"
p:prefix="/WEB-INF/"
p:suffix=".jsp" /> </beans>

到这里还并没有完成,我开始把包含css的floder放在WEB-INF目录下,发现还是不能引入css,后来我把那个floder放在WebRoot目录下成功引入了!

Spring MVC:在jsp中引入css的更多相关文章

  1. 使用Maven构建Java Web项目时,关于jsp中引入js、css文件路径问题。

    今天有点闲,自己动手搭建一个Java Web项目,遇到jsp中引入js.css文件时路径不正确的问题,于是在网上查阅了很多资料,最终都无法解决问题,于是,上stackoverflow找到了解决方法,这 ...

  2. Java 本地开发环境搭建(框架采用 Spring+Spring MVC+Hibernate+Jsp+Gradle+tomcat+mysql5.6)

    项目搭建采用技术栈为:Spring+Spring MVC+Hibernate+Jsp+Gradle+tomcat+mysql5.6 搭建环境文档目录结构说明: 使用Intellj Idea 搭建项目过 ...

  3. 如何在jsp中引入bootstrap

    如何在jsp中引入bootstrap包: 1.首先在http://getbootstrap.com/上下载Bootstrap的最新版. 您会看到两个按钮: Download Bootstrap:下载 ...

  4. 【JSP中引入文件】JSP中获取根路径+引用js文件

    在jsp界面中经常需要引入js.css等文件,通常都需要先获取项目根路径,然后再引入文件. 例如: 项目路径如下,需要在index.jsp中引入FusionCharts相关的js.css等: inde ...

  5. spring mvc在Controller中获取ApplicationContext

    spring mvc在Controller中获取ApplicationContext web.xml中进行正常的beans.xml和spring-mvc.xml的配置: 需要在beans.xml中进行 ...

  6. HTML中引入CSS的方法

    在HTML中引入CSS的方法主要有四种,它们分别是行内式.内嵌式.链接式和导入式. 1.行内式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现出CSS的优势,不推荐使用. 2.内嵌式 ...

  7. HTML中引入CSS的四种常用方法及各自的缺点

    在HTML中引入CSS的方法主要有四种,它们分别是行内式.内嵌式.链接式和导入式. 1.行内式 行内式是在标记的style属性中设定CSS样式.这种方式没有体现出CSS的优势,不推荐使用.格式如下: ...

  8. 在html中引入css、js和jQuery的方法

    在html中引入css代码 在html中插入CSS样式表的方法有三种: 1.外部样式表(External style sheet):即所有的样式单独写在一个.css文件中,在html文件的head部分 ...

  9. Spring MVC 使用tomcat中配置的数据源

    Spring MVC 使用tomcat中配置的数据源 配置tomcat数据源 打开tomcat目录下的conf目录,编辑sever.xml目录.在<GlobalNamingResources&g ...

随机推荐

  1. redmine问题集锦

    当我新建LDAP认证模式时,遇到如下错误:

  2. 网络流n题 题解

    学会了网络流,就经常闲的没事儿刷网络流--于是乎来一发题解. 1. COGS2093 花园的守护之神 题意:给定一个带权无向图,问至少删除多少条边才能使得s-t最短路的长度变长. 用Dijkstra或 ...

  3. iOS App禁止横屏

    修改Info.plist文件Supported interface orientations的项目 该项目是字典 把Landscape相关的键值删除即可

  4. js中数组连接concat()

    数组连接concat() concat() 方法用于连接两个或多个数组.此方法返回一个新数组,不改变原来的数组. 语法 arrayObject.concat(array1,array2,...,arr ...

  5. VS更改编辑窗背景

    打开Visual Studio  工具→扩展和更新→联机  在搜索框里输入“background”后,搜索结果有很多插件可以更改 Visual Studio 的背景,选择其中的一项,可以在右边进行预览 ...

  6. Loadrunner监控Linux系统资源

    一.安装rsh和rpcbind 1.查看是否安装:rpm -qa |grep rsh 2.安装rsh:yum -y install rsh* 3.yum  -y install nfs-utils r ...

  7. devexpress layoutcontrol 自动生成布局示例代码

    foreach (var row in lst.Select(x => x.crow).Distinct()) { LayoutControlItem layout_preitem = null ...

  8. ios数据永久存储之----NSUserDefaults

    我们在开发app时不可避免的会在本地存储一些数据,NSUserDefaults就是系统提供的一个用来数据存储的类,本片文章就来介绍一些NSserdefazults的用法. 详细内容:https://m ...

  9. T-SQL 基础学习 04

    索引        示意图 定义 索引提供指针指向存储在表中指定列的数据值,然后根据指定的排序次序排列这些指针 作用 通过使用索引,大大提高数据库的检索速度,改善数据库性能 索引六大类 1.      ...

  10. MySQL - 问题集 - "Got error 28 from storage engine"

    数据库的临时目录空间不够,修改配置文件中的tmpdir,指向一个硬盘空间很大的目录即可. windows下,找到配置文件my.ini. [mysqld] tmpdir=D:/work/tool/mys ...