博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
spring-MVC访问静态资源
阅读量:4677 次
发布时间:2019-06-09

本文共 1737 字,大约阅读时间需要 5 分钟。

Since I spent a lot of time on this issue, I thought I'd share my solution. Since spring 3.0.4, there is a configuration parameter that is called <mvc:resources/> (more about that on the ) which can be used to serve static resources while still using the DispatchServlet on your site's root.

In order to use this, use a directory structure that looks like the following:

src/ springmvc/  web/   MyController.javaWebContent/  resources/   img/    image.jpg  WEB-INF/    jsp/      index.jsp    web.xml    springmvc-servlet.xml
 

The contents of the files should look like:

src/springmvc/web/HelloWorldController.java:

1 package springmvc.web; 2  3 import org.springframework.stereotype.Controller; 4 import org.springframework.web.bind.annotation.RequestMapping; 5  6 @Controller 7 publicclassHelloWorldController{ 8  9  @RequestMapping(value="/")10  publicString index(){11   return"index";12  }13 }

 

 

WebContent/WEB-INF/web.xml:

1 
2
6 7
8
springmvc
9
org.springframework.web.servlet.DispatcherServlet
10
1
11
12 13
14
springmvc
15
/
16
17

 

 

WebContent/WEB-INF/springmvc-servlet.xml:

1 
2
11 12
13
14 15
16
17 18
19
20
22 23 24
25
27
29
30
31 32 33

 

 

WebContent/jsp/index.jsp:

1 <%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>2 

Page with image

3
4 " />

 

 

Hope this helps :-)

转载于:https://www.cnblogs.com/JavaTechLover/archive/2012/09/01/spring-access-staticResources.html

你可能感兴趣的文章
JVM
查看>>
设计模式记录
查看>>
SPF,DSPF,RDPF,SPEF and SBPF.
查看>>
JS学习文章
查看>>
window系统服务器,远程连接mysql数据库。
查看>>
CAS总结之Ticket篇
查看>>
Python2.7升级至Python3.6
查看>>
框架集
查看>>
003
查看>>
HDU 2923 Einbahnstrasse (最短路,3级)
查看>>
实验吧-密码学-我喜欢培根
查看>>
java set集合与List集合练习
查看>>
简短总结一下C#里跨线程更新UI
查看>>
201612-2 工资计算
查看>>
DevExpress下拉多选框 CheckComboboxEdit、CheckedListBoxControl
查看>>
MySQL 忘记Root密码
查看>>
WPF后台自定义文字带背景的选择状态按钮
查看>>
【转自Mgen】 .NET(C#):谈谈各种结束进程的方法
查看>>
ERROR 2002 (HY000): Can't connect to local MySQL server through socket '/tmp/mysql.sock' (2)
查看>>
用原生javascript做的一个打地鼠的小游戏
查看>>