Solve the problem of chasing code in JSP

zhaozj2021-02-16  53

The database store is best used in the format of 8859_1, so when the database is stored, the coding conversion is made, but we usually display the format of GB2312 or GBK, so turn it again when it takes out.

E.g:

Use: Turn data into the format name of 8859_1 Name = new string (Name.getbytes), "GB2312"), "8859_1"); content = new string (Content.getbytes ("GB2312"), "8859_1") ;

INSERT INTO (Name, Content) Values ​​(?,?) .......

From the database when taken with: Connection con = DriverManager.getConnection ( "jdbc: mysql:? // localhost / gfqqqqpe user = gfqqqqpe_f & password = aaaaa & useUnicode = true; characterEncoding = 8859_1"); to specify the database when taken coding mode is "8859_1 ", Then display it when converting: name = new string (name.getbytes)," GB2312 ")," GB2312 "); this method is universal on MySQL

// Processing a custom function of Chinese <%! 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) {E.PrintStackTrace ();} return "null";}%>

转载请注明原文地址:https://www.9cbs.com/read-21551.html

New Post(0)