한자를 입력하고 "제출"버튼을 클릭하면 입력한 한자의 병음이 자동으로 입력됩니다. 이 구현 방법은 인터넷에서 찾았지만 좀 더 명확하게 사용하기 위해 몇 가지 수정했습니다.
질문이 있으시면 저에게 연락해주세요: [email protected]
<%...@ 페이지 언어="java" import="java.util.*" contentType="text/html; charset=GBK" %>
<%...!
해시테이블 ht=new Hashtable(10);
문자열 g(정수 n){
int num=n.intValue();
if(숫자>0&&숫자<160){
return String.valueOf((char)num);
}
else if(숫자<-20319||숫자>-10247){
반품 "";
}
또 다른{
if(ht.size()==0){b();}
while(!ht.containsKey(Integer.toString(num)))num--;
return ht.get(Integer.toString(num)).toString();
}
}
문자열 c(문자열 str){
char[] hz=str.toCharArray();
int len=str.length();
int p,q;
문자열 ret="";
for(int i=0;i<len;i++){
p=(int)hz[i];
만약(p>160){
q=(int)hz[++i];
p=p*256+q-65536;
}
ret+=g(새로운 정수(p));
ret=ret+"<b>"+String.valueOf(p)+"</b><br>";
}
반환 ret;
}
무효 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","금지");
ht.put("-20242","뱅");
ht.put("-20230","바오");
ht.put("-20051","베이");
ht.put("-20036","벤");
ht.put("-20032","벵");
ht.put("-20026","bi");
ht.put("-20002","bian");
ht.put("-19990","biao");
ht.put("-19986","bie");
ht.put("-19982","bin");
ht.put("-19976","빙");
ht.put("-19805","bo");
ht.put("-19784","bu");
ht.put("-19775","ca");
ht.put("-19774","cai");
ht.put("-19763","할 수 있습니다");
ht.put("-19756","캉");
ht.put("-19751","cao");
ht.put("-19746","ce");
ht.put("-19741","셍");
ht.put("-19739","cha");
ht.put("-19728","차이");
ht.put("-19725","찬");
ht.put("-19715","창");
ht.put("-19540","chao");
ht.put("-19531","체");
ht.put("-19525","첸");
ht.put("-19515","쳉");
ht.put("-19500","chi");
ht.put("-19484","총");
ht.put("-19479","슈");
ht.put("-19467","추");
ht.put("-19289","추아이");
ht.put("-19288","추안");
ht.put("-19281","추앙");
ht.put("-19275","추이");
ht.put("-19270","춘");
ht.put("-19263","츄오");
ht.put("-19261","ci");
ht.put("-19249","콩");
ht.put("-19243","cou");
ht.put("-19242","cu");
ht.put("-19238","cuan");
ht.put("-19235","cui");
ht.put("-19227","쿤");
ht.put("-19224","cuo");
ht.put("-19218","da");
ht.put("-19212","dai");
ht.put("-19038","dan");
ht.put("-19023","댕");
ht.put("-19018","다오");
ht.put("-19006","de");
ht.put("-19003","뎅");
ht.put("-18996","di");
ht.put("-18977","dian");
ht.put("-18961","디아오");
ht.put("-18952","죽음");
ht.put("-18783","딩");
ht.put("-18774","diu");
ht.put("-18773","동");
ht.put("-18763","dou");
ht.put("-18756","du");
ht.put("-18741","duan");
ht.put("-18735","dui");
ht.put("-18731","dun");
ht.put("-18722","듀오");
ht.put("-18710","e");
ht.put("-18697","en");
ht.put("-18696","er");
ht.put("-18526","fa");
ht.put("-18518","팬");
ht.put("-18501","송곳니");
ht.put("-18490","fei");
ht.put("-18478","펜");
ht.put("-18463","펭");
ht.put("-18448","fo");
ht.put("-18447","fou");
ht.put("-18446","푸");
ht.put("-18239","ga");
ht.put("-18237","gai");
ht.put("-18231","gan");
ht.put("-18220","갱");
ht.put("-18211","가오");
ht.put("-18201","ge");
ht.put("-18184","gei");
ht.put("-18183","gen");
ht.put("-18181","geng");
ht.put("-18012","공");
ht.put("-17997","구");
ht.put("-17988","gu");
ht.put("-17970","gua");
ht.put("-17964","과이");
ht.put("-17961","구안");
ht.put("-17950","광");
ht.put("-17947","gui");
ht.put("-17931","총");
ht.put("-17928","구오");
ht.put("-17922","하");
ht.put("-17759","하이");
ht.put("-17752","한");
ht.put("-17733","멈춤");
ht.put("-17730","하오");
ht.put("-17721","그");
ht.put("-17703","헤이");
ht.put("-17701","암탉");
ht.put("-17697","헹");
ht.put("-17692","홍");
ht.put("-17683","당신");
ht.put("-17676","hu");
ht.put("-17496","화");
ht.put("-17487","화이");
ht.put("-17482","환");
ht.put("-17468","황");
ht.put("-17454","hui");
ht.put("-17433","훈");
ht.put("-17427","huo");
ht.put("-17417","지");
ht.put("-17202","지아");
ht.put("-17185","지안");
ht.put("-16983","장");
ht.put("-16970","자오");
ht.put("-16942","jie");
ht.put("-16915","진");
ht.put("-16733","징");
ht.put("-16708","지옹");
ht.put("-16706","지우");
ht.put("-16689","ju");
ht.put("-16664","juan");
ht.put("-16657","jue");
ht.put("-16647","jun");
ht.put("-16474","ka");
ht.put("-16470","카이");
ht.put("-16465","칸");
ht.put("-16459","강");
ht.put("-16452","카오");
ht.put("-16448","ke");
ht.put("-16433","켄");
ht.put("-16429","켁");
ht.put("-16427","콩");
ht.put("-16423","코우");
ht.put("-16419","ku");
ht.put("-16412","쿠아");
ht.put("-16407","쿠아이");
ht.put("-16403","쿠안");
ht.put("-16401","쿠앙");
ht.put("-16393","kui");
ht.put("-16220","군");
ht.put("-16216","쿠오");
ht.put("-16212","la");
ht.put("-16205","lai");
ht.put("-16202","lan");
ht.put("-16187","lang");
ht.put("-16180","lao");
ht.put("-16171","le");
ht.put("-16169","레이");
ht.put("-16158","길이");
ht.put("-16155","li");
ht.put("-15959","lia");
ht.put("-15958","리안");
ht.put("-15944","량");
ht.put("-15933","liao");
ht.put("-15920","거짓말");
ht.put("-15915","lin");
ht.put("-15903","링");
ht.put("-15889","리우");
ht.put("-15878","긴");
ht.put("-15707","루");
ht.put("-15701","lu");
ht.put("-15681","lv");
ht.put("-15667","루안");
ht.put("-15661","루");
ht.put("-15659","lun");
ht.put("-15652","루오");
ht.put("-15640","ma");
ht.put("-15631","mai");
ht.put("-15625","남자");
ht.put("-15454","망");
ht.put("-15448","마오");
ht.put("-15436","나");
ht.put("-15435","메이");
ht.put("-15419","남자");
ht.put("-15416","멩");
ht.put("-15408","mi");
ht.put("-15394","mian");
ht.put("-15385","미아오");
ht.put("-15377","미에");
ht.put("-15375","최소");
ht.put("-15369","밍");
ht.put("-15363","miu");
ht.put("-15362","mo");
ht.put("-15183","mou");
ht.put("-15180","뮤");
ht.put("-15165","na");
ht.put("-15158","나이");
ht.put("-15153","nan");
ht.put("-15150","낭");
ht.put("-15149","나오");
ht.put("-15144","ne");
ht.put("-15143","nei");
ht.put("-15141","넨");
ht.put("-15140","neng");
ht.put("-15139","ni");
ht.put("-15128","니안");
ht.put("-15121","냐앙");
ht.put("-15119","niao");
ht.put("-15117","니");
ht.put("-15110","닌");
ht.put("-15109","닝");
ht.put("-14941","niu");
ht.put("-14937","농");
ht.put("-14933","nu");
ht.put("-14930","nv");
ht.put("-14929","누안");
ht.put("-14928","누");
ht.put("-14926","누오");
ht.put("-14922","o");
ht.put("-14921","ou");
ht.put("-14914","pa");
ht.put("-14908","pai");
ht.put("-14902","팬");
ht.put("-14894","팡");
ht.put("-14889","pao");
ht.put("-14882","페이");
ht.put("-14873","펜");
ht.put("-14871","펭");
ht.put("-14857","pi");
ht.put("-14678","피안");
ht.put("-14674","피아오");
ht.put("-14670","파이");
ht.put("-14668","핀");
ht.put("-14663","핑");
ht.put("-14654","po");
ht.put("-14645","pu");
ht.put("-14630","qi");
ht.put("-14594","qia");
ht.put("-14429","qian");
ht.put("-14407","치앙");
ht.put("-14399","qiao");
ht.put("-14384","qie");
ht.put("-14379","qin");
ht.put("-14368","칭");
ht.put("-14355","qiong");
ht.put("-14353","qiu");
ht.put("-14345","qu");
ht.put("-14170","quan");
ht.put("-14159","que");
ht.put("-14151","qun");
ht.put("-14149","란");
ht.put("-14145","rang");
ht.put("-14140","rao");
ht.put("-14137","re");
ht.put("-14135","ren");
ht.put("-14125","렝");
ht.put("-14123","ri");
ht.put("-14122","롱");
ht.put("-14112","rou");
ht.put("-14109","ru");
ht.put("-14099","루안");
ht.put("-14097","루이");
ht.put("-14094","실행");
ht.put("-14092","루오");
ht.put("-14090","sa");
ht.put("-14087","sai");
ht.put("-14083","san");
ht.put("-13917","노래");
ht.put("-13914","sao");
ht.put("-13910","se");
ht.put("-13907","센");
ht.put("-13906","셍");
ht.put("-13905","샤");
ht.put("-13896","샤이");
ht.put("-13894","샨");
ht.put("-13878","상");
ht.put("-13870","샤오");
ht.put("-13859","그녀");
ht.put("-13847","쉔");
ht.put("-13831","셩");
ht.put("-13658","시");
ht.put("-13611","수");
ht.put("-13601","슈");
ht.put("-13406","슈아");
ht.put("-13404","슈아이");
ht.put("-13400","슈안");
ht.put("-13398","슈앙");
ht.put("-13395","슈이");
ht.put("-13391","순");
ht.put("-13387","슈오");
ht.put("-13383","si");
ht.put("-13367","노래");
ht.put("-13359","sou");
ht.put("-13356","su");
ht.put("-13343","수안");
ht.put("-13340","sui");
ht.put("-13329","태양");
ht.put("-13326","suo");
ht.put("-13318","ta");
ht.put("-13147","타이");
ht.put("-13138","tan");
ht.put("-13120","탱");
ht.put("-13107","타오");
ht.put("-13096","te");
ht.put("-13095","텡");
ht.put("-13091","ti");
ht.put("-13076","티안");
ht.put("-13068","티아오");
ht.put("-13063","넥타이");
ht.put("-13060","ting");
ht.put("-12888","통");
ht.put("-12875","tou");
ht.put("-12871","tu");
ht.put("-12860","tuan");
ht.put("-12858","tui");
ht.put("-12852","tun");
ht.put("-12849","tuo");
ht.put("-12838","wa");
ht.put("-12831","wai");
ht.put("-12829","완");
ht.put("-12812","왕");
ht.put("-12802","wei");
ht.put("-12607","원");
ht.put("-12597","웽");
ht.put("-12594","wo");
ht.put("-12585","우");
ht.put("-12556","xi");
ht.put("-12359","xia");
ht.put("-12346","시안");
ht.put("-12320","샹");
ht.put("-12300","샤오");
ht.put("-12120","xie");
ht.put("-12099","xin");
ht.put("-12089","싱");
ht.put("-12074","xiong");
ht.put("-12067","xiu");
ht.put("-12058","xu");
ht.put("-12039","쉬안");
ht.put("-11867","xue");
ht.put("-11861","xun");
ht.put("-11847","야");
ht.put("-11831","yan");
ht.put("-11798","양");
ht.put("-11781","야오");
ht.put("-11604","예");
ht.put("-11589","yi");
ht.put("-11536","음");
ht.put("-11358","잉");
ht.put("-11340","yo");
ht.put("-11339","용");
ht.put("-11324","당신");
ht.put("-11303","yu");
ht.put("-11097","위안");
ht.put("-11077","yue");
ht.put("-11067","윤");
ht.put("-11055","za");
ht.put("-11052","zai");
ht.put("-11045","zan");
ht.put("-11041","장");
ht.put("-11038","zao");
ht.put("-11024","ze");
ht.put("-11020","zei");
ht.put("-11019","zen");
ht.put("-11018","젱");
ht.put("-11014","zha");
ht.put("-10838","자이");
ht.put("-10832","잔");
ht.put("-10815","장");
ht.put("-10800","자오");
ht.put("-10790","zhe");
ht.put("-10780","젠");
ht.put("-10764","젱");
ht.put("-10587","zhi");
ht.put("-10544","종");
ht.put("-10533","저우");
ht.put("-10519","주");
ht.put("-10331","zhua");
ht.put("-10329","주아이");
ht.put("-10328","zhuan");
ht.put("-10322","좡어");
ht.put("-10315","주이");
ht.put("-10309","준");
ht.put("-10307","zhuo");
ht.put("-10296","zi");
ht.put("-10281","종");
ht.put("-10274","zou");
ht.put("-10270","zu");
ht.put("-10262","zuan");
ht.put("-10260","zui");
ht.put("-10256","zun");
ht.put("-10254","zuo");
ht.put("-10247","zz");
}
%>
<%...
if(request.getParameter("hz")!=null)
{
out.println(c(request.getParameter("hz")));
}
%>
<양식 방법=게시물>
여기에 중국어를 입력하세요: <입력 이름=hz>
<입력 유형="제출" 값="제출">
</form>
입력 및 출력 결과 형식은 다음과 같습니다.
예: "여기에 중국어를 입력하십시오"를 입력
하면 출력 결과는
qing-14357
입니다.
자이-11046
ci-19253
츄-19290
슈-13596
ru-14101
종-10544
Wen-12604
는 병음으로 쓰여 있고 그 뒤에 계산된 코드가 나옵니다(왜 이런 숫자가 나오는지 모르겠습니다). 가끔 한자가 흔하게 사용되지 않고 추가되지 않으면 코드만 표시되고, 코드는 표시되지 않습니다. 현재로서는 ht.put("-10247","zz"); 형식으로 추가할 수 있습니다.