解决乱麻的问题
<H3 >字符的格式处理<o:p></o:p></H3><P ><FONT face="Times New Roman"> </FONT>由于在网页和数据库对于汉字的处理用的格式是不相同的,必须有个格式转换的类,<FONT face="Times New Roman">FormatConvert.java </FONT>用来处理字符格式的转换<FONT face="Times New Roman">.</FONT></P>
<P ><FONT face="Times New Roman">package Format;</FONT></P>
<P ><FONT face="Times New Roman">import java.io.IOException;</FONT></P>
<P ><FONT face="Times New Roman">import java.io.UnsupportedEncodingException;</FONT></P>
<P ><FONT face="Times New Roman">import java.lang.String;</FONT></P>
<P ><FONT face="Times New Roman"> <o:p></o:p></FONT></P>
<P ><FONT face="Times New Roman">public class FormatConvert {</FONT></P>
<P ><FONT face="Times New Roman"> public FormatConvert()</FONT></P>
<P ><FONT face="Times New Roman"> {}</FONT></P>
<P ><FONT face="Times New Roman"> public String convert(String str) throws UnsupportedEncodingException,IOException</FONT></P>
<P ><FONT face="Times New Roman">{</FONT></P>
<P ><FONT face="Times New Roman"> //</FONT>把数据库中的汉字准确的转换到网页中</P>
<P ><FONT face="Times New Roman"> if(str==null||str.length()<1)</FONT></P>
<P ><FONT face="Times New Roman"> str="";</FONT></P>
<P ><FONT face="Times New Roman"> else</FONT></P>
<P ><FONT face="Times New Roman"> {</FONT></P>
<P ><FONT face="Times New Roman"> str=(new String(str.getBytes("iso-8859-1"),"GB2312"));</FONT></P>
<P ><FONT face="Times New Roman"> return str;</FONT></P>
<P ><FONT face="Times New Roman"> }</FONT></P>
<P ><FONT face="Times New Roman"> </FONT></P>
<P ><FONT face="Times New Roman"> return str;</FONT></P>
<P ><FONT face="Times New Roman"> </FONT></P>
<P ><FONT face="Times New Roman"> }</FONT></P>
<P ><FONT face="Times New Roman"> public String reConvert(String str )throws UnsupportedEncodingException,IOException</FONT></P>
<P ><FONT face="Times New Roman">{</FONT></P>
<P ><FONT face="Times New Roman"> ///</FONT>把网页中的汉字准确的转换到数据库中</P>
<P ><FONT face="Times New Roman"> if(str==null||str.length()<1)</FONT></P>
<P ><FONT face="Times New Roman"> str="";</FONT></P>
<P ><FONT face="Times New Roman"> else</FONT></P>
<P ><FONT face="Times New Roman"> { String temp=new String();</FONT></P>
<P ><FONT face="Times New Roman"> temp=(new String(str.getBytes("GB2312"),"iso-8859-1"));</FONT></P>
<P ><FONT face="Times New Roman"> return temp;</FONT></P>
<P ><FONT face="Times New Roman"> }</FONT></P>
<P ><FONT face="Times New Roman"> </FONT></P>
<P ><FONT face="Times New Roman"> return str;</FONT></P>
<P ><FONT face="Times New Roman"> }</FONT></P>
<P ><FONT face="Times New Roman">}</FONT></P>
页:
[1]
