jsp转码类

来源:互联网 发布:平面设计网站 知乎 编辑:程序博客网 时间:2024/06/05 19:26

package db;

import java.io.UnsupportedEncodingException;

public class ChangeChar {

 public ChangeChar() {
 }

 public static String Char(String str) {
  String value = "";
  String check = System.getProperty("os.name").toLowerCase();
  if (str != null)
   try {
    if (check.indexOf("win") != -1) {
     value = new String(str.getBytes("ISO-8859-1"));
    } else {
     value = new String(str.getBytes(), "GB2312");
    }
   } catch (UnsupportedEncodingException ex) {
    ex.printStackTrace();
   }
  return value;
 }

 public String gb2iso(String qs) {
  try {
   if (qs == null)
    return "NULL";
   else
    return new String(qs.getBytes("gb2312"), "iso-8859-1");
  } catch (Exception e) {
  }
  return "NULL";
 }
 
 public String Convert(String s){

  String result = null;

  byte[] temp = null ;

  try {
   temp = s.getBytes("iso-8859-1");
  } catch (UnsupportedEncodingException e) {
   // TODO 自动生成 catch 块
   e.printStackTrace();
  }

  try {
   result =  new String(temp,"utf-8");
  } catch (UnsupportedEncodingException e) {
   // TODO 自动生成 catch 块
   e.printStackTrace();
  }
  return result;

  }
 
 public String Convert1(String s){

  String result = null;

  byte[] temp = null ;

  try {
   temp = s.getBytes("utf-8");
  } catch (UnsupportedEncodingException e) {
   // TODO 自动生成 catch 块
   e.printStackTrace();
  }

  try {
   result =  new String(temp,"iso-8859-1");
  } catch (UnsupportedEncodingException e) {
   // TODO 自动生成 catch 块
   e.printStackTrace();
  }
  return result;

  }

 

}

原创粉丝点击