1. garbled characters about the FORM parameters received by jsp (preferred for SUN Enterprise Applications:
<%@ page contentType="text/html;charset=GB2312" %> <! --/* For tomcat (a very useful JSP running platform) 4. Use jsp (preferred for SUN Enterprise applications) to generate Chinese garbled characters. Define a conversion function getStr ()! --> <%! Public String getStr (String str ){ Try {String temp_p = str; Byte [] temp_t = temp_p.getBytes ("ISO8859-1 "); String temp = new String (temp_t ); Return temp; } Catch (Exception e ){} Return "NULL "; } %> <! --------------------- The end -------------------- */-->
|
2. garbled characters about the Form parameters received by Servlet.
File Name: ThreeParams. java:
Package moreservlets; import java. io. *; import javax. servlet. *; import javax. servlet. http. *; public class ThreeParams extends HttpServlet {// defines a function getStr () to solve the problem of garbled form parameters. public String getStr (String str) {try {String temp_p = str; byte [] temp_t = temp_p.getBytes ("ISO8859-1"); String temp = new String (temp_t); return temp;} catch (Exception e) {} return "NULL ";} // -- receives and displays the three parameters sent from form. Note that the third parameter is not converted and can be used for comparison. public void doGet (HttpServletRequest request, HttpServletResponse response) throws IOException, ServletException {response. setContentType ("text/html; charset = GB2312"); PrintWriter out = response. getWriter (); String docType = "<! Doctype html public "-// W3C // dtd html 4.0" + "Transitional // EN"> "; out. println (docType + "<HTML>" + "<BODY>" + getStr (request. getParameter ("param1") + "<BR>" + getStr (request. getParameter ("param2") + "<BR>" + request. getParameter ("param3") + "<BR>" + "<center>
|
3. How to Deal with Chinese garbled characters when connecting to the Sybase Database Using jConnect:
Make sure that the database uses a Chinese character set, such as eucgb, utf8, and cp936. At the same time, set the necessary connection attributes during jconnect programming, including charset (which must be consistent with the database) and jconnect_version.
For example:
Jconnect 4.2:
Jdbc: sybase: Tds: hostname: port/dbname? Charset = eucgb & jconnect_version = 4
Jconnect 5.2:
Jdbc: sybase: Tds: hostname: port/dbname? Charset = eucgb & jconnect_version = 0 |