解决JSP中文乱码问题

来源:互联网 发布:大型分析仪器仿真软件 编辑:程序博客网 时间:2024/05/20 17:07

1. JSP页面中文乱码问题

在页面开始处设置如下属性 <%@ page language=”java” contentType=”text/html; charset=gb2312” %> 或者是 <%@ page language=”java” contentType=”text/html; charset=UTF-8”%>


2 . 在输出和获取中文信息时,出现乱码. 如表单参数的获取等

解决方案一:
在输出和获取中文信息时使用“ISO-8859”编码

    public String ChangeEnconding(String str){        String s = str;    try{        byte[]temp = s.getBytes("ISO-8859-1");        s = new String(temp);        return s;}    catch(Exception e){        System.out.print(e.toString());        return s;    }

解决方案二:
设置从request中取得的值的编码,此设置只适合post方式
request.setCharacterEncoding(“utf-8”);


0 0