These days develop a project, the server is Tomcat, the operating system is XP, which is the MVC architecture. The mode is used in the FACADE mode. It has always been garbled. I also solved it for many days. Colleagues also help solve, and more thanks to many netizens. Articles and opinions, it is finally available. But good memory is not as bad, so I deliberately, to prevent yourself from forgotten, and also provide a good reference path to those who encounter the same problem: (1) The JSP page is Chinese, but it is a garbled : Solving the way is the coded problem in the JSP page code <% @ page language = "java" contentty = "text / html; charset = GBK"%> The server is ISO-8859-1. If a JSP is directly entered, JSP is handled as ISO8859-1 is definitely problematic, this, we can confirm by viewing JAVA intermediate files generated by Jasper ( 2) When using the REQUEST object to obtain the Chinese character code submitted by the customer, there will be garbled: Solution to configure a filter, which is a server filter, code as follows: import java.ioException; import javax. servlet.Filter; import javax.servlet.FilterChain; import javax.servlet.FilterConfig; import javax.servlet.ServletException; import javax.servlet.ServletRequest; import javax.servlet.ServletResponse; import javax.servlet.UnavailableException;
/ ** * EXAMPLE FILTER THATE STS The Character Encoding to Be Used In Parsing The * Incoming Request * / Public Class SetCharacterencodingFilter Implements Filter {
/ ** * Take this filter out of service. * / Public void destroy () {} / ** * Select and set (if specified) the character encoding to be used to * interpret request parameters for this request. * / Public void DOFILTER (ServletRequest Request, ServletResponse Response, Filterchain Chain) throws ioException, servletexception {
Request.SetCharacterencoding ("GBK");
// Pass control to the next filter chain.dofilter (request, response);
public void init (FilterConfig filterConfig) throws ServletException {}} configured web.xml
Public String Touni (String gbstr) {string unistr = ""; if (gbstr == null) {GBSTR = "";} try {byte [] tempbyte = gbstr.getbytes ("GB2312"); Unistr = New String (Tempbyte , "ISO8859_1");} Catch (Exception EX) {} Return Unistr;}} You can also transform directly, first you will get the obtained string with ISO-8859-1, then store this code to one In-byte arrays, then convert this array into string objects, for example: string str = request.getParameter ("girl"); Byte B [] = Str.getbytes ("ISO-8859-1"); Str = new string (b); any information submitted correctly by the above conversion. (3) Returning in the server-only request. GetParameter ("Name") is garbled; Press Tomcat to set Filter and use Request.SetCharacterencoding ("GBK"); no matter what the problem is On the method of processing parameters: If you have a DOGET (HTTPSERVLETREST, HTTPSERVLETRESE RESPONS) method, even write: Request.SetCharacterencoding ("gbk"); response.setContentType ("text / html; charSet = GBK "); also does not work, return Chinese or garbled! ! ! If this function is changed to dopost (httpservletRequest request, httpservletResponse response) everything is OK. Similarly, the meaning of the display can be displayed in two JSP page processing forms is because the POST method is transmitted, it is still not possible to change to the GET method. This shows that in the servlet uses a doget () method or in the JSP to use the GET method to handle it. This is, involving passing parameter information to pass through the browser, which is likely to cause conflicts of common character sets or do not match. The solution is: 1) Open Tomcat's server.xml file, find blocks, add the following line: uriencoding = "GBK" is the following:
2) Restart Tomcat, everything OK. Reasons for need to join you can find this file under the Tomcat_Home / WebApps / Tomcat-DOCS / Config / Http.html. It should be noted that this place If you use UTF-8, you should have garbled in the Tomcat during the transfer, if you don't work, you will change your character set.
(4) There are Chinese on the JSP page, and there are Chinese on the button, but there is a garbled when viewing the page through the server: Solution: First, you should not directly contain localized message text in the JSP file, but should pass
Context> The bold is particularly paying special attention. It is different from the JDBC direct link. If you are configuring the correctization, when you enter Chinese, it is Chinese, there is a point to pay attention to it. Is the page you want to display data in displaying data, this line code is also used <% @ page language = ". It should be noted that some of the front desk is written in writing code. When writing a Form, he changed him to a JSP, so there is a place to pay attention, that is, in Dreamver's Action The way is Request, you need to take him, because in the process of JSP's submission, it is POST and GET in two ways, but the code submitted in these two ways is still very different in the coding, this is The later places will be described. 3 or more is what I solve Chinese in the development system. I don't know if I can solve everyone's problems. Time is in a hurry, I have not timely and improve, I'm not very good, some are estimated is the word. You can give me your opinion and hope to make progress together.