ssm一些不需要记住的配置

配置上传解析器
1
2
3
4
5
6
7
8
9
<bean id="multipartResolver" class="org.springframework.web.multipart.commons.CommonsMultipartResolver">
<!-- 设置上传文件的最大尺寸为1MB -->
<property name="maxUploadSize">
<!-- spring el写法:1MB -->
<value>#{1024*1024}</value>
</property>
     <!-- 效果同上 -->
<property name="maxUploadSize" value="1048576" />
</bean>
解决下载中文乱码问题
1
2
3
4
5
6
7
8
9
//ie浏览器
if(req.getHeader("User-Agent").toUpperCase().indexOf("TRIDENT")!=-1){
filename = URLEncoder.encode(filename, "utf-8");
//电脑自带edge【edʒ】浏览器
}else if(req.getHeader("User-Agent").toUpperCase().indexOf("EDGE")!=-1){
filename = URLEncoder.encode(filename, "utf-8");
}else{//其他浏览器
filename = new String(filename.getBytes("UTF-8"),"ISO-8859-1");//转码的方式
};
解决浏览器自动解析文件展示问题
1
2
//设置文件下载的名字  -- 附件表示做下载或上传操作,浏览器就不会将文件的内容直接显示出来了
resp.setHeader("Content-Disposition", "attachment; filename=" + name);
配置拦截器
1
2
3
4
5
6
7
8
9
10
11
12
<!-- 配置拦截器组 -->
<mvc:interceptors>
<!-- 拦截器 -->
<mvc:interceptor>
<!-- 要拦截的配置,该配置必须写在不拦截的上面,/*拦截一级请求,/**拦截多级请求 -->
<mvc:mapping path="/**"  />
<!-- 设置不拦截的配置 -->
<mvc:exclude-mapping path="/login"/>
<!-- 配置拦截器 -->
<bean class="cn.itsource.springmvc._06_interceptor.MyInterceptor" />  
</mvc:interceptor>
</mvc:interceptors>

Comments: