web.xml 、springmvc.xml、applicationcontext*.xml
先列个大纲,后面把一些细节补充进来
一、web.xml
web.xml是统一入口,在web.xml配置其他2个xml的引用。
1、默认页面
<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>
参考:https://blog.youkuaiyun.com/sinat_36220051/article/details/80239430
2、编码
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>utf-8</param-value>
</init-param>
</filter>
有的说加上:
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
指定响应的编号等于encoding。我的没有这样设置,但我的@ResponseBody方法返回json也没乱码啊。
------好像是因为我返回前端的都是对象,所以不会乱码,如果是string 指定了response编码就不乱码了。

3、过滤器(filter)
上面的编码控制就是一个过滤器。
4、监听器(listener)
servlet
二、springmvc.xml
视图解析器
注解
数据类型转换
拦截器
跨域
swagger
资源映射
上传文件配置
读取resources配置
三、applicationcontext*.xml
dao(数据库配置)
transaction(事务)
ehcache(缓存)
websocket
本文围绕Java Web项目中的web.xml、springmvc.xml和applicationcontext*.xml展开。web.xml是统一入口,可配置默认页面、编码、过滤器和监听器等;springmvc.xml涉及视图解析器、注解、数据类型转换等;applicationcontext*.xml包含数据库配置、事务和缓存等内容。
1169

被折叠的 条评论
为什么被折叠?



