Spring MVC 使用 静态资源

  • 页面引入jstl标签库
<%@taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>

  • 项目的目录如下图所示:

  • Spring Mvc 的配置文件写成下面这样子
  • 注意几个地方:
    • xmlns:mvc
    • xsi:schemaLocation
    • mvc:resources
    • mvc:annotation-driven
<?xml version= "1.0" encoding ="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
    xmlns:context="http://www.springframework.org/schema/context"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:mvc="http://www.springframework.org/schema/mvc"
    xsi:schemaLocation="
 http://www.springframework.org/schema/beans
 http://www.springframework.org/schema/beans/spring-beans-4.0.xsd
 http://www.springframework.org/schema/mvc
 http://www.springframework.org/schema/mvc/spring-mvc.xsd
 http://www.springframework.org/schema/context
 http://www.springframework.org/schema/context/spring-context-4.0.xsd">

    <context:component-scan base-package="com.forum.www.controller" />

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

    <mvc:resources mapping="/jquery/**" location="/resource/jquery/"
        cache-period="31556926" />

    <mvc:resources mapping="/bootstrap/**" location="/resource/bootstrap/"
        cache-period="31556926" />

    <mvc:annotation-driven />
</beans>


页面这样引入css和js:

<link href="<c:url value="/bootstrap/css/bootstrap.min.css" />"
    rel="stylesheet">

<script src="<c:url value="/jquery/jquery-1.11.3.min.js" />"></script>
<script src="<c:url value="/bootstrap/js/bootstrap.min.js" />"></script>
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值