<mvc:resources mapping="/xxx/**" location="/xxx/"/>无效,可能和Controller的URL模式有关
某项目webapp下有子目录res,其中有img、css、js等存放静态资源的文件夹。
在定义了dispacher-servlet的<url-pattern>/</url-pattern>后,
<!-- 配置DispatcherServlet -->
<servlet>
<servlet-name>dispatcher</servlet-name>
<servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
<load-on-startup>1</load-on-startup>
</servlet>
<servlet-mapping>
<servlet-name>dispatcher</servlet-name>
<url-pattern>/</url-pattern>
</servlet-mapping>
为访问静态资源,特别在dispacher-servlet.xml定义了<mvc:resource/>标签
<!-- 注解驱动 -->
<mvc:annotation-driven /> <!-- 静态资源访问,约定:静态资源都放在web应用根的res文件夹中 -->
<mvc:resources location="/res/" mapping="/res/**" />
随后定义了HomeController,如下:
@Controller
public class HomeController { @RequestMapping(method=RequestMethod.GET)
public String home() {
return "home";
}
}
结果,无法访问静态资源
为Controller加上url模式,
@Controller
public class HomeController { @RequestMapping(value="/", method=RequestMethod.GET)
public String home() {
return "home";
}
}
之后,访问静态资源正常了。
<mvc:resources mapping="/xxx/**" location="/xxx/"/>无效,可能和Controller的URL模式有关的更多相关文章
- 关于spring 3.0.5的 <mvc:resources mapping="***" location="***">标签的使用
spring mvc 的<mvc;resources mapping="***" location="***">标签是在spring3.0.4出现的 ...
- 增加mvc:resources后访问不了注解配置的controller的问题
刚开始没有配置mvc:resourcescontroller能够正确访问,但是由于web.xml使用/拦截了所有的请求,所以静态资源访问不上增加mvc:resources之后,静态资源是能访问上了,但 ...
- SpringMVC同时使用<mvc:resources … />和日期转换Formatter时出现问题的解决方法
很久没更新博文了,不是没有学习,而是很多东西记在OneNote里面,收获很多啊,因为各种杂事,所以对于博客很久没更新了. 个人觉得:博客比起OneNote或者为知笔记之类的云笔不同在于博客应该记载的是 ...
- Spring MVC ,使用mvc:resources标签后,处理器无法被访问
在SpringMVC的配置文件中添加了<mvc:resources mapping="/img/**" location="/img/"/>以便处理 ...
- SpringMVC 的<mvc:resources>使用映射路径展示文件服务器上的图片
<servlet> <servlet-name>springMVC</servlet-name> <servlet-class>org.springfr ...
- springMVC配置静态资源访问的<mvc:resources>标签的使用
在springmvc中,为了引用资源的访问不会类似Controller一样被拦截,区分出关注的资源的访问,一般我们在springMVC里面的拦截都会配置为"/",拦截所有的.但是这 ...
- Spring mvc <mvc:resources ***/> 作用
<!-- 配置静态资源,直接映射到对应的文件夹,不被DispatcherServlet处理,3.04新增功能,需要重新设置spring-mvc-3.0.xsd --> 如在页面需要导入其它 ...
- cvc-complex-type.2.4.c: The matching wildcard is strict, but no declaration can be found for element 'mvc:resources'.
新的错误出现 spring-mvc.xml文件 <mvc:resources mapping="/static/**" location="/static/&qu ...
- mvc:resources
springmvc 配置静态文件 http://static.springsource.org/spring/docs/3.0.x/spring-framework-reference/html/mv ...
随机推荐
- sqlite 使用 cte 及 递归的实现示例
1.多级 cte 查询示例. with cte as ( select pageid from cm_bookpage ) , cte2 as ( as content from cte ) sele ...
- magento 1.9 nginx 404
原来的nginx 配置 lnmp 环境默认的 location ~ [^/]\.php(/|$) { fastcgi_param SCRIPT_FILENAME $document_root$fast ...
- python selenium-webdriver 处理JS弹出对话框(六)
在实际系统中,在完成某些操作时会弹出对话框来提示,主要分为"警告消息框","确认消息框","提示消息对话"三种类型的对话框. 1.警告消息框 ...
- ningx.conf location
server { listen ; server_name localhost; location /dirName { alias "C:/Users/VALEB/Downloads/in ...
- 利用redis List队列简单实现秒杀 PHP代码实现
一 生产者producer部分 --------------------------------producer 部分注释--------------------------------------- ...
- vue 将毫秒转为日期
12345656546 | parseTime('{y}-{m}-{d} {h}:{i}')
- python 画图工具matplotlib 去掉坐标轴和坐标的方法
1. 去掉坐标轴的方法: plt.axis('off') 2.去掉刻度的方法: plt.xticks([]) plt.yticks([]) 以上语句需要将其置于 plt.show() 之前,plt.i ...
- 17款提高编码效率的CSS工具
摘要:作为WEB前端开发人员,你的工作可能很大一部分都在编写CSS代码,为了提高前端开发人员编写CSS代码的效率,编程文库从 网上搜集了17款可以提高你CSS代码效率的CSS工具,它们可以帮助你快速生 ...
- Oracle 外键级联更新
Oracle数据库中,外键约束只允许级联删除,不允许级联更新,因此,如果想要实现主表数据更新后,子表外键自动更新,只能取消外键关系,通过前端程序来维护实现完整引用,一个代替的解决方案是使用延迟约束和触 ...
- [原创] JAVA 递归线程池测试 ExecutorService / ForkJoinPool
测试工具使用递归的方式获取子进程的Msg消息,目前有2种常用的ExecutorService / ForkJoinPool 为了测试哪种效果较好,我们来写个测试Demo,循环5555555次+1(加锁 ...