您的位置:首页 >> Web开发 >> JSP技术 >> JSP实例 >> 正文
JSP实例 RSS
 

汉字转化为拼音(jsp版)

http://www.rdxx.com 02年05月21日 12:12 Blog 我要投稿

关键词: 转化 , 汉字 , 拼音 , JSP

很多问题都是因为中文问题造成的
如文件名最好别用中文
现在的解决方法一般是产生一个ID,将这个ID做文件名
网页上如果url带汉字也经常出错
现在的解决方法一般用urlencode编码

现在用了这个转化,就好多了

原理:利用哈希表技术   Hashtable ht=new Hashtable(10);

1.添加索引,如: ht.put("-20295","ang");
2.倒序遍历,如:  while(!ht.containsKey(Integer.toString(num)))num--;

<%@ page language="java" import="java.util.*" contentType="text/html" %>
<%!
Hashtable ht=new Hashtable(10);
String g(Integer n){
 int num=n.intValue();
 if(num>0&&num<160){
  return String.valueOf((char)num);
 }
 else if(num<-20319||num>-10247){
  return "";
 }
 else{
  if(ht.size()==0){b();}
  while(!ht.containsKey(Integer.toString(num)))num--;
  return ht.get(Integer.toString(num)).toString();
 }
}
String c(String str){
 char[] hz=str.toCharArray();
 int len=str.length();
 int p,q;
 String ret="";
 for(int i=0;i<len;i++){
  p=(int)hz[i];
  if(p>160){
   q=(int)hz[++i];
   p=p*256+q-65536;
  }
  ret+=g(new Integer(p));
 }
 return ret;
}
void b(){
 ht.put("-20319","a");
 ht.put("-20317","ai");
 ht.put("-20304","an");
 ht.put("-20295","ang");
 ht.put("-20292","ao");
 ht.put("-20283","ba");
 ht.put("-20265","bai");
 ht.put("-20257","ban");
 ht.put("-20242","bang");
 ht.put("-20230","bao");
 ht.put("-20051","bei");
 ht.put("-20036","ben");
 ht.put("-20032","beng");
 ht.put("-20026","bi");
 ht.put("-20002","bian");
 ht.put("-19990","biao");
 ht.put("-19986","bie");
 ht.put("-19982","bin");
 ht.put("-19976","bing");
 ht.put("-19805","bo");
 ht.put("-19784","bu");
 ht.put("-19775","ca");
 ht.put("-19774","cai");
 ht.put("-19763","can");
 ht.put("-19756","cang");
 ht.put("-19751","cao");
 ht.put("-19746","ce");
 ht.put("-19741","ceng");
 ht.put("-19739","cha");
 ht.put("-19728","chai");
 ht.put("-19725","chan");
 ht.put("-19715","chang");
 ht.put("-19540","chao");
 ht.put("-19531","che");
 ht.put("-19525","chen");
 ht.put("-19515","cheng");
 ht.put("-19500","chi");
 ht.put("-19484","chong");
 ht.put("-19479","chou");
 ht.put("-19467","chu");
 ht.put("-19289","chuai");
 ht.put("-19288","chuan");
 ht.put("-19281","chuang");
 ht.put("-19275","chui");
 ht.put("-19270","chun");
 ht.put("-19263","chuo");
 ht.put("-19261","ci");
 ht.put("-19249","cong");
 ht.put("-19243","cou");
 ht.put("-19242","cu");
 ht.put("-19238","cuan");
 ht.put("-19235","cui");
 ht.put("-19227","cun");
 ht.put("-19224","cuo");
 ht.put("-19218","da");
 ht.put("-19212","dai");
 ht.put("-19038","dan");
 ht.put("-19023","dang");
 ht.put("-19018","dao");
 ht.put("-19006","de");
 ht.put("-19003","deng");

共5页  1 2 3 4 5

 
 
标签: 转化 , 汉字 , 拼音 , JSP 打印本文
 
 
  热点搜索
 
 
 



Valid XHTML 1.0 Transitional
Copyright ©2005 - 2008 Rdxx.Com,All Rights Reserved
收藏本页
收藏本站