Spring MVC 静态资源访问 mvc:resources 标签
来源:互联网 发布:怎样生成淘宝客链接 编辑:程序博客网 时间:2024/04/29 03:10
最近又开始了 Java Web 之旅 很久没有做了,复习一下 Spring,Spring MVC和Mybatis。
使用的版本是 Spring 4的核心库,在配置静态资源的时候出了一些问题。
我把静态资源整合在了一个 public 文件夹下 然后配置了
<mvc:resources location="/public/" mapping="/public/**"></mvc:resources>
然而并没有什么卵用,百度了一下,七七八八都说需要加上下面这句话
<mvc:annotation-driven />
加载注解映射器和适配器我已经配置了,这就郁闷了,搞了半天,发现一个很细节的问题,我的资源放在了WEB-INF下,看了下网上的说法,个人观点同意把静态资源
放在WEB-INF下,因为安全。这下问题就很明朗了我在标签下加了一句话
<mvc:resources location="/WEB-INF/public/" mapping="/public/**"></mvc:resources>
最后贴一下 我的配置 springmvc.xml(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:mvc="http://www.springframework.org/schema/mvc"xmlns:context="http://www.springframework.org/schema/context"xsi:schemaLocation="http://www.springframework.org/schema/mvc http://www.springframework.org/schema/mvc/spring-mvc-4.1.xsdhttp://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans.xsdhttp://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-4.1.xsd"><mvc:annotation-driven /><!-- 对静态资源文件的访问 方案一 --><mvc:resources location="/WEB-INF/public/" mapping="/public/**"></mvc:resources><!-- 使用扫描的方法加载Handler --><context:component-scan base-package="com.leo.ssm.controller" /><beanclass="org.springframework.web.servlet.view.InternalResourceViewResolver"><!-- 配置前缀和后缀 简化 url路径的设置 --><property name="prefix" value="/WEB-INF/" /><property name="suffix" value=".jsp" /></bean></beans>
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"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>ExjModel</display-name><!-- 加载spring容器 --><context-param><param-name>contextConfigLocation</param-name><param-value>/WEB-INF/classes/spring/applicationContext-*.xml</param-value></context-param><listener><listener-class>org.springframework.web.context.ContextLoaderListener</listener-class></listener><!-- Spring mvc 前端控制器 --><servlet><servlet-name>springmvc</servlet-name><servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class><init-param><param-name>contextConfigLocation</param-name><param-value>classpath:spring/springmvc.xml</param-value></init-param><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>springmvc</servlet-name><url-pattern>/</url-pattern></servlet-mapping><welcome-file-list><welcome-file>index.html</welcome-file><welcome-file>index.htm</welcome-file><welcome-file>index.jsp</welcome-file><welcome-file>default.html</welcome-file><welcome-file>default.htm</welcome-file><welcome-file>default.jsp</welcome-file></welcome-file-list></web-app>
工程目录结构
0 0
- Spring MVC 静态资源访问 mvc:resources 标签
- spring<mvc:resources> 标签的使用 静态资源的访问
- Spring : 使用<mvc:resources 访问静态资源
- spring mvc:resources 静态资源访问
- Spring MVC中使用resources标签映射静态资源
- MVC静态资源映射 <mvc:resources> 标签的使用
- Spring MVC 静态资源访问
- springMvc里的mvc:resources与静态资源的访问
- springMvc里的mvc:resources与静态资源的访问
- springMvc里的mvc:resources与静态资源的访问
- springMvc里的mvc:resources与静态资源的访问
- springMvc里的mvc:resources与静态资源的访问
- springMvc里的mvc:resources与静态资源的访问
- Spring MVC 表单标签 & 处理静态资源
- spring-mvc访问静态资源iO类
- Spring MVC 静态资源的访问
- spring mvc 访问静态资源404
- Spring MVC访问不到静态资源
- chatrr权限
- ZOJ 3492Kagome Kagome
- 【树莓派】更新软件源之后更新报错
- Bootstrap 多媒体对象和列表组
- libpng的png_read_info和png_read_image使用实例分析
- Spring MVC 静态资源访问 mvc:resources 标签
- C#封装自己的函数,并且引用
- 四种算法 Dijkstra bellman spfa Floyd 模版
- ZOJ 3497Mistwald
- Java基础程序设计(一)
- ubuntu下配置tomcat
- Python基础语法——循环(一)
- photoshop第十五章:制作商业卡片场景效果
- VMWare Workstation虚拟机访问外网