jsp乱码

来源:互联网 发布:淘宝助理定时上架步骤 编辑:程序博客网 时间:2024/05/20 00:38
编码方式:
ISO8859-1
UTF-8   
gb2312  
GBK     

例如:
“汉字”
GBK:    %BA%BA%D7%D6
UTF-8:    %E6%B1%89%E5%AD%97

***
JSP

1.<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
设置JSP编译成Servlet时使用的编码。
JSP页面内存在汉字字符等。

2.<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
指定对服务器响应进行重新编码的编码。服务器在将数据发送到浏览器前,对数据进行重新编码时,使用的就是该编码。

3.request.setCharacterEncoding("UTF-8")
使用filter,过滤器。
表单提交过来的数据进行编码。

此方法只能解决POST提交的数据。

4.server.xml中配置useBodyEncodingForURI="true"
URL数据和GET提交的数据,才能根据request.setCharacterEncoding("UTF-8")进行重新编码。

***

参考文章:
1.JSP中文乱码解决方案-Tomcat5.0版
http://hi.baidu.com/aviscx/blog/item/90af8001a35a75d6267fb5e1.html
原创粉丝点击