- 浏览: 3377579 次
- 性别:
- 来自: 珠海
文章分类
- 全部博客 (1633)
- Java (250)
- Android&HTML5 (111)
- Struts (10)
- Spring (236)
- Hibernate&MyBatis (115)
- SSH (49)
- jQuery插件收集 (55)
- Javascript (145)
- PHP (77)
- REST&WebService (18)
- BIRT (27)
- .NET (7)
- Database (105)
- 设计模式 (16)
- 自动化和测试 (19)
- Maven&Ant (43)
- 工作流 (36)
- 开源应用 (156)
- 其他 (16)
- 前台&美工 (119)
- 工作积累 (0)
- OS&Docker (83)
- Python&爬虫 (28)
- 工具软件 (157)
- 问题收集 (61)
- OFbiz (6)
- noSQL (12)
最新评论
-
HEZR曾嶸:
你好博主,这个不是很理解,能解释一下嘛//左边+1,上边+1, ...
java 两字符串相似度计算算法 -
天使建站:
写得不错,可以看这里,和这里的这篇文章一起看,有 ...
jquery 遍历对象、数组、集合 -
xue88ming:
很有用,谢谢
@PathVariable映射出现错误: Name for argument type -
jnjeC:
厉害,困扰了我很久
MyBatis排序时使用order by 动态参数时需要注意,用$而不是# -
TopLongMan:
非常好,很实用啊。。
PostgreSQL递归查询实现树状结构查询
输入信息乱码
@RequestParam传值中文乱码
http://luanxiyuan.iteye.com/blog/1849169
使用代码手动转换
返回信息乱码
方法一:
http://blog.csdn.net/kissliux/article/details/14053761
采用了一个比较简单的方法来解决这个问题,就是需要服务器返回中文的时候不使用这个注解,而是直接用HttpServletResponse的对象来完成传输,在服务器端可以通过response.setContentType("text/plain;charset=UTF-8");来设定编码类型,这样就不会出现中文乱码了。
服务器端核心代码如下:
返回值时根据自己的数据类型进行设置,常用的有:
response.setContentType("text/html; charset=utf-8"); html
response.setContentType("text/plain; charset=utf-8"); 文本
response.setContentType("application/json; charset=utf-8"); 数据
response.setContentType("application/xml; charset=utf-8"); xml
方法二:@ResponseBody乱码
http://blog.csdn.net/kissliux/article/details/14053761
spring-servlet 配置
controller中
转换类:
@RequestParam传值中文乱码
http://luanxiyuan.iteye.com/blog/1849169
使用代码手动转换
try { return new String(str.getBytes(fromCharset), toCharset); } catch (Exception e) { e.printStackTrace(); return null; }
返回信息乱码
方法一:
http://blog.csdn.net/kissliux/article/details/14053761
采用了一个比较简单的方法来解决这个问题,就是需要服务器返回中文的时候不使用这个注解,而是直接用HttpServletResponse的对象来完成传输,在服务器端可以通过response.setContentType("text/plain;charset=UTF-8");来设定编码类型,这样就不会出现中文乱码了。
服务器端核心代码如下:
@RequestMapping(value = "test", method = RequestMethod.POST) public void test(HttpServletRequest request, HttpServletResponse response) { String result = null; //取得客户端传来的值 String userName = request.getParameter("userName"); //向客户端返回一句话 result = "您好!"; PrintWriter out = null; response.setContentType("text/plain;charset=UTF-8"); try { out = response.getWriter(); out.write(result.toString()); } catch (IOException e) { e.printStackTrace(); } finally { out.close(); } }
返回值时根据自己的数据类型进行设置,常用的有:
response.setContentType("text/html; charset=utf-8"); html
response.setContentType("text/plain; charset=utf-8"); 文本
response.setContentType("application/json; charset=utf-8"); 数据
response.setContentType("application/xml; charset=utf-8"); xml
方法二:@ResponseBody乱码
http://blog.csdn.net/kissliux/article/details/14053761
spring-servlet 配置
<mvc:annotation-driven> <mvc:message-converters register-defaults="true"> <bean class="com.abc.spring.UTF8StringHttpMessageConverter"/> </mvc:message-converters> </mvc:annotation-driven>
controller中
@RequestMapping(value = "/getWeather",method = {RequestMethod.POST,RequestMethod.GET},produces="text/plain;charset=UTF-8") @ResponseBody
转换类:
public class UTF8StringHttpMessageConverter extends AbstractHttpMessageConverter<String> { public static final Charset DEFAULT_CHARSET = Charset.forName("UTF-8"); private final List<Charset> availableCharsets; public UTF8StringHttpMessageConverter() { this(DEFAULT_CHARSET); } public UTF8StringHttpMessageConverter(Charset defaultCharset) { super(new MediaType("text", "plain", defaultCharset), MediaType.ALL); this.availableCharsets = new ArrayList<Charset>(Charset .availableCharsets().values()); } @Override protected boolean supports(Class<?> clazz) { return String.class.equals(clazz); } @Override protected String readInternal(Class<? extends String> clazz, HttpInputMessage inputMessage) throws IOException, HttpMessageNotReadableException { MediaType contentType = inputMessage.getHeaders().getContentType(); Charset charset = contentType.getCharSet() != null ? contentType .getCharSet() : DEFAULT_CHARSET; return FileCopyUtils.copyToString(new InputStreamReader(inputMessage .getBody(), charset)); } @Override protected void writeInternal(String t, HttpOutputMessage outputMessage) throws IOException, HttpMessageNotWritableException { MediaType contentType = outputMessage.getHeaders().getContentType(); Charset charset = contentType.getCharSet() != null ? contentType .getCharSet() : DEFAULT_CHARSET; FileCopyUtils.copy(t, new OutputStreamWriter(outputMessage.getBody(), charset)); } protected List<Charset> getAcceptedCharsets() { return this.availableCharsets; } @Override protected Long getContentLength(String s, MediaType contentType) { if (contentType != null && contentType.getCharSet() != null) { Charset charset = contentType.getCharSet(); try { return (long) s.getBytes(charset.name()).length; } catch (UnsupportedEncodingException ex) { throw new InternalError(ex.getMessage()); } } else { return null; } } }
发表评论
-
Spring Boot 属性配置
2016-06-24 11:04 1155Spring Boot 属性配置和使用 http://blog ... -
Spring Boot 集成MyBatis
2016-06-24 10:55 1999Spring Boot 集成MyBatis http://bl ... -
Spring MVC防重复提交
2016-06-17 15:47 1601http://my.oschina.net/zyqjustin ... -
Spring容器加载完之后执行特定任务
2016-06-17 15:36 2251http://my.oschina.net/simpleton ... -
使用spring-session和shiro来代理session的配置
2016-06-16 11:21 12008使用spring-session和redis来代理sessio ... -
JSTL 的 if else : 有 c:if 没有 else 的处理
2016-06-14 09:52 1306http://blog.csdn.net/xiyuan1999 ... -
spring mvc 请求转发和重定向
2016-06-14 09:48 1362http://blog.csdn.net/jackpk/art ... -
mvc:view-controller
2016-05-18 10:26 1057http://blog.csdn.net/lzwglory/a ... -
spring配置事物的方式:注解和aop配置
2016-05-14 00:26 4073参考: Spring AOP中pointcut express ... -
分布式任务调度组件 Uncode-Schedule
2016-05-13 14:47 2257http://www.oschina.net/p/uncode ... -
Mybatis分库分表扩展插件
2016-05-12 15:47 1597http://fangjialong.iteye.com/bl ... -
spring+mybatis+atomikos 实现JTA事务
2016-05-11 22:00 5487sping配置多个数据源 不同用户操作不同数据库 http:/ ... -
Spring中使用注解 @Scheduled执行定时任务
2016-05-10 09:39 1545原文:http://dwf07223.blog.51cto.c ... -
Spring中配置Websocket
2016-05-05 16:55 1256spring+websocket整合(springMVC+sp ... -
redis 集群中Session解决方案之Spring Session
2016-05-04 08:54 1282集群中Session解决方案之Spring Session h ... -
使用Spring-data进行Redis操作
2016-05-04 08:54 4745使用Spring-data进行Redis操作 http://z ... -
Spring4新特性——集成Bean Validation 1.1(JSR-349)到SpringMVC
2016-05-03 13:35 1036Spring4新特性——集成Bean Validation 1 ... -
SpringMVC介绍之Validation
2016-05-03 13:10 960SpringMVC介绍之Validation http://h ... -
spring 注解方式下使用commons-validator 验证表单
2016-05-03 11:08 3049原文: http://www.programgo.com/ar ... -
Spring MVC学习详解
2016-04-28 09:13 974原文 http://blog.csdn.net/alsocod ...
相关推荐
本例子提供了2中 springMVC 上传的例子,通过 ajax 提交的方式,通过 Form 提交的方式,同时获取上传后文件名称,支持多个文件上传。
springMVC支持ajax的jar包,包括 jackson-annotations-2.1.5.jar jackson-core-2.1.4.jar jackson-databind-2.4.3.jar
springmvc+ajax上传例子
使用springMVC+ajax+json的一个小demo,希望对读者有用
SpringMVC注解return参数出现乱码解决方案。
springMVC jQuery ajax交互的简单的应用,一个可以参照的文件
SpringMVC+Ajax异步文件上传+短视频背景+a标签绑定文件域
SpringMVC 接收 Ajax 请求注意事项 SpringMVC 框架在处理 Ajax 请求时需要注意一些重要的配置和设置,以确保请求的正确处理和数据的正确传输。下面我们将介绍在 SpringMVC 中接收 Ajax 请求的注意事项。 基本数据...
springmvc 上传下载文件,支持 ajax,form 提交,支持 multiple 方式上传文件
Ajax实现异步请求+基于SpringMVC
Springmvc与Ajax交互实例
NULL 博文链接:https://stillcoolme.iteye.com/blog/2313624
SpringMVC利用Ajax,JQuery交互Json
三个ajax与springmvc的交互的demo
使用Ajax从页面向控制层请求数据,并将提交的数据再次返回,国外网站下载代码,很有参考意义。请使用Eclipse工具
springMVC ajax实例 内副js、jsp、java类 根据需要,可自行更改
http://blog.csdn.net/madcode2222222222222/article/details/78326347
springMVC框架遇到中文乱码的解决思路汇总,包括从配置到注解的详细描述,帮助开发人员解决spirngMVC中文乱码问题
一个实用了spring mvc和ajax异步请求的例子
sprinmvc框架 demo spring+springmvc HIbernate