版权声明:https://blog.csdn.net/qq_40224714?t=1 https://blog.csdn.net/qq_40224714/article/details/89043890
1、静态资源配置
spring mvc对静态资源的管理,加载不到js、css等的静态资源
在springmvc中配置如下:
<mvc:default-servlet-handler />
<?xml version="1.0" encoding="UTF-8"?>
<beans xmlns="http://www.springframework.org/schema/beans"
xmlns:mvc="http://www.springframework.org/schema/mvc"
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"
xsi:schemaLocation="
http://www.springframework.org/schema/beans
http://www.springframework.org/schema/beans/spring-beans.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.xsd">
<!-- 自动扫描组件 -->
<context:component-scan base-package="com.cn.lyl.controller"/>
<!-- 打开注解驱动 -->
<mvc:annotation-driven/>
<!-- 静态资源路径配置,js、css、img -->
<mvc:default-servlet-handler />
<!-- 配置jsp视图解析器 ,需要有jstl这个jar包,否则不能映射-->
<bean id="viewResolver" class="org.springframework.web.servlet.view.InternalResourceViewResolver">
<property name="viewClass" value="org.springframework.web.servlet.view.JstlView"/>
<property name="prefix" value="/WEB-INF/jsp/"/>
<property name="suffix" value=".jsp"/>
</bean>
</beans>