1 Always use UTF-8 as encoding;
2 Try to set the encoding uniformly(in filter or web server side);
2.1 In tomcat6,
2.1.1 For get method, you may set encoding by adding URIEncoding cfg option in server.xml:
<Connector connectionTimeout="20000" port="8080" protocol="HTTP/1.1" redirectPort="8443" URIEncoding="UTF-8"/>
2.1.2 For post method, you can only set encoding by request.setCharacterEncoding in your filter(Don't call any request.getParameter before request.setCharacterEncoding, or request.setCharacterEncoding will not take effect).
2.2 In weblogic 10.3, you may set encoding in 2 ways:
2.2.1 In filter, request.setCharacterEncoding will set the encoding for both post method and get method;
2.2.2 In weblogic.xml, the following setting will set the encoding for both post method and get method:
<wls:charset-params>
<wls:input-charset>
<wls:resource-path>/cvsearch/*</wls:resource-path>
<wls:java-charset-name>UTF-8</wls:java-charset-name>
</wls:input-charset>
</wls:charset-params>
3 In servlet, set the encoding of response before sending result to client: response.setContentType("text/javascript; charset=UTF-8");
4 In jsp page, set the charset attribute of contentType to UTF-8: <%@page contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
Some more scenario for encoding:
----------------------------------
1) String.getBytes()
String s = "a";
s.getBytes("UTF-8");
----------------------------------
2) jstl core import
<c:import url="/ajax/topMover_CDS_getAxisSeries.action" charEncoding="UTF-8"/>
----------------------------------
3) InputStreamReader
InputStream is = this.getClass().getClassLoader().getResourceAsStream(fileName);
BufferedReader br = new BufferedReader(new InputStreamReader(is, "utf-8"));
分享到:
相关推荐
Chapter 9: Best Practices for Function-Based Views Chapter 10: Best Practices for Class-Based Views Chapter 11: Form Fundamentals Chapter 12: Common Patterns for Forms Chapter 13: Templates: Best ...
NHTSA_Cybersecurity Best Practices for Modern Vehicles
High Performance Spark Best Practices for Scaling and Optimizing Apache Spark 英文epub 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
High Performance Spark Best Practices for Scaling and Optimizing Apache Spark 英文azw3 本资源转载自网络,如有侵权,请联系上传者或csdn删除 本资源转载自网络,如有侵权,请联系上传者或csdn删除
Defensive Security Handbook: Best Practices for Securing Infrastructure by Lee Brotherston English | 3 Apr. 2017 | ASIN: B06Y18XC5Y | 268 Pages | AZW3 | 3.88 MB Despite the increase of high-profile ...
AWS Best Practices for DDoS Resiliency,是基于AWS上安全服务shield和WAF ALB和cloudfont已经Route53构建适合不同应用部署架构的防拒绝服务攻击的文档,可以帮助用户设计适合的防护机制。
Best Practices for Upgrades to Oracle Database 11g Release 2 CN
Building Software Teams: Ten Best Practices for Effective Software Development English | 31 Dec. 2016 | ISBN: 149195177X | 136 Pages | AZW3/MOBI/EPUB/PDF (conv) | 6.49 MB Why does poor software ...
High Performance Spark Best Practices for Scaling and Optimizing Apache Spark 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权,请联系上传者或...
Learning Spark Streaming Best Practices for Scaling and Optimizing Apache Spark(Early Release) 英文无水印pdf pdf所有页面使用FoxitReader和PDF-XChangeViewer测试都可以打开 本资源转载自网络,如有侵权...
"High Performance Spark Best Practices for Scaling and Optimizing Apache Spark" 这一主题深入探讨了如何最大化利用Spark的性能,以及如何进行有效扩展和优化。以下是一些关键的知识点: 1. **资源管理与调度**...
High Performance Spark: Best Practices for Scaling and Optimizing Apache Spark by Holden Karau English | 25 May 2017 | ASIN: B0725YT69J | 358 Pages | AZW3 | 3.09 MB Apache Spark is amazing when ...
1. SAP Best Practices for SAP S/4HANA - This package provides preconfigured processes and content specifically designed for the SAP S/4HANA platform. It helps customers implement the latest business ...
《微服务最佳实践 for Java》是由IBM公司推出的英文版指南,深入探讨了在Java环境中实现微服务架构的各种最佳策略和技巧。微服务架构是一种将单一应用程序拆分为一组小型、独立的服务的方法,每个服务都能在其自己的...
现代车辆的网络安全已经成为一个备受关注的问题,因为随着车辆智能化和互联化程度的不断提升,其面临的网络攻击风险也随之增加。车辆制造商和售后市场设备制造商都需要采取一系列网络安全最佳实践,以确保现代车辆的...
This document is intended to help those with a basic knowledge of machine learning get the benefit of best practices in machine learning from around Google. It presents a style for machine learning,...
Best Practices for Performance Sending Operations to Multiple Threads
VMware vSphere是VMware公司推出的一款服务器虚拟化平台,它可以实现数据中心的自动化、资源优化和业务连续性。iSCSI(Internet Small Computer System Interface)是一种使用TCP/IP网络存储的协议,允许通过IP网络...
Best Practices for Programming Eclipse and OSGi.pdf Best Practices for Programming Eclipse and OSGi.pdf