当前位置:网站首页>中文编码的设置与action方法的返回值
中文编码的设置与action方法的返回值
2022-07-31 17:11:00 【是庸医啊】
目录
中文编码设置
<filter>
<filter-name>encode</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<!--
配置参数
private String encoding;
private boolean forceRequestEncoding;
private boolean forceResponseEncoding;
-->
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceRequestEncoding</param-name>
<param-value>true</param-value>
</init-param>
<init-param>
<param-name>forceResponseEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encode</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
测试中文编码过滤器
全部改成post,然后再提交!
action方法的返回值
返回值有String、void、基础类型、Model、ModelAndView、Map、自定义类、自定义输出内容、@ResponseBody修饰等。
1)String:客户端资源的地址,自动拼接前缀和后缀,还可以屏蔽自动拼接字符串,可以指定返回的路径
2)Object:返回json格式的对象,自动将对象或集合转为json,使用的是Jackson工具进行转换,必须要提那家jackson依赖,一般用户ajax请求
3)void:无返回值,一般用于ajax请求
4)基本数据类型,用于ajax请求
5)ModelAndView:返回数据和视图对象
完成ajax请求访问服务器
(1)添加jackson依赖
添加中文编码
(2)在webapp目录下新建js目录,添加jQuery函数库
(3)在index.jsp页面上导入函数库
(4)在action上添加注解@ResponseBody,用来出来ajax请求
(5)在springmvc.xml文件中添加注解驱动<mvc:annotationdriven/>,它用来解析@ResponseBody注解。
如何搭建Spring项目,修改目录,修改pom.xml文件?_是庸医啊的博客-CSDN博客
<dependency>
<groupId>com.fasterxml.jackson.core</groupId>
<artifactId>jackson-databind</artifactId>
<version>2.9.8</version>
</dependency>
边栏推荐
- The server encountered an internal error that prevented it from fulfilling this request的一种解决办法[通俗易懂]
- Combinatorics Notes (6) Associative Algebra of Locally Finite Partially Ordered Sets, Möbius Inversion Formula
- 认识异常 (看完这篇你就懂了)
- After the form is submitted, the page does not jump [easy to understand]
- Design and Implementation of Compiler Based on C Language
- 牛客网刷题(四)
- 【C语言】LeetCode27.移除元素
- 最后写入胜利(丢弃并发写入)
- 使用 Postman 工具高效管理和测试 SAP ABAP OData 服务的试读版
- Last write wins (discards concurrent writes)
猜你喜欢
Flex布局详解
2022年整理LeetCode最新刷题攻略分享(附中文详细题解)
宁波大学NBU IT项目管理期末考试知识点整理
Jiuqi ny3p series voice chip replaces the domestic solution KT148A, which is more cost-effective and has a length of 420 seconds
【C语言】LeetCode27.移除元素
MySQL---多表查询
新型电信“套路”,我爸中招了!
Kotlin coroutines: continuation, continuation interceptor, scheduler
仿生毛毛虫机器人源码
动态规划之线性dp(上)
随机推荐
After the form is submitted, the page does not jump [easy to understand]
无主复制系统(2)-读写quorum
Anaconda如何顺利安装CV2
6. 使用 Postman 工具高效管理和测试 SAP ABAP OData 服务
【码蹄集新手村600题】通向公式与程序相结合
[pytorch] pytorch automatic derivation, Tensor and Autograd
Masterless replication system (1) - write DB when node fails
多数据中心操作和检测并发写入
牛客网刷题(三)
华为手机一键开启“维修模式”隐藏所有数据,让手机隐私更加安全
牛客 HJ16 购物单
BOW/DOM(上)
入职一个月反思
GP 6 overall architecture study notes
Small program: Matlab solves differential equations "recommended collection"
Go1.18升级功能 - 模糊测试Fuzz 从零开始Go语言
Mariabackup实现Mariadb 10.3的增量数据备份
Golang go-redis cluster模式下不断创建新连接,效率下降问题解决
这位985教授火了!当了10年博导,竟无一博士毕业!
MySQL---单行函数