当前位置:网站首页>中文编码的设置与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>
边栏推荐
猜你喜欢

Bika LIMS 开源LIMS集—— SENAITE的使用(检测流程)

Huawei mobile phone one-click to open "maintenance mode" to hide all data and make mobile phone privacy more secure

Three aspects of Ali: How to solve the problem of MQ message loss, duplication and backlog?

【码蹄集新手村600题】不通过字符数组来合并俩个数字
![[Network Communication 3] Advantech Gateway Modbus Service Settings](/img/ec/e9e1d9a374183ecaa8a8c9437ec82c.png)
[Network Communication 3] Advantech Gateway Modbus Service Settings

你辛辛苦苦写的文章可能不是你的原创

useragent在线查找

动态规划之线性dp(上)

This 985 professor is on fire!After 10 years of Ph.D. supervisor, no one has graduated with a Ph.D.!

认识异常 (看完这篇你就懂了)
随机推荐
【愚公系列】2022年07月 Go教学课程 021-Go容器之切片操作
MySQL---聚合函数
Kotlin协程:续体、续体拦截器、调度器
iNeuOS工业互联网操作系统,设备运维业务和“低代码”表单开发工具
【愚公系列】2022年07月 Go教学课程 022-Go容器之字典
浅谈网络安全之算法安全
上传图片-微信小程序(那些年的坑记录2022.4)
动态规划(一)
Masterless replication system (1) - write DB when node fails
【NLP】什么是模型的记忆力!
牛客网刷题(四)
BOW/DOM(上)
[pytorch] 1.7 pytorch and numpy, tensor and array conversion
华为顶级工程师历时9年总结的“趣谈网络协议”PDF文档,太强了
LevelSequence源码分析
【Yugong Series】July 2022 Go Teaching Course 022-Dictionary of Go Containers
Kotlin coroutines: continuation, continuation interceptor, scheduler
牛客网刷题(一)
AcWing 1282. Search Keyword Problem Solution ((AC Automata) Trie+KMP)+bfs)
这位985教授火了!当了10年博导,竟无一博士毕业!