对请求重新进行编码 (解决中文乱码)

来源:互联网 发布:华凯网络 编辑:程序博客网 时间:2024/05/22 02:15

<%@ page contentType="text/html; charset=gb2312"%>

<%@ page import="java.io.*"%>

<%

     ! String trans(String chi) {

            String result = null;

            byte temp[];

            try {

               temp=chi.getBytes("iso-8859-1");

               result = new String(temp);

             } catch(UnsupportedEncodingException e) {

                System.out.println(e.toString());

           }

         return result;

   }

%>

<%

    out.println(trans(request.getParameter("name")));

%>

 

另外还有一种很简单的方法

request.setCharacterEncoding("gb2312");

原创粉丝点击