Recently, using struts 1.1, the annoying Chinese garbled problem is found, and the process of forming the Form will appear at the time.
The method I found on the web is as follows:
(Tomcat 5.0.28 Struts 1.1 Hibernate 2.1 SQLServer2K)
1. Directly convert the public static string isotogb (string src) {string strret = null; try {strret = new string (src.getbytes ("ISO_8859_1"), "GB2312");} Catch (Exception E) {} Return Strret } Into a function to enter code, I have no success, I don't know why!
2. Filter Filter Setting Method
Package yourbean;
Import javax.servlet. *; import javax.servlet.http. *; import java.io. *; import java.util. *;
public class servfilter extends HttpServlet implements Filter {private FilterConfig filterConfig; // Handle the passed-in FilterConfig public void init (FilterConfig filterConfig) {this.filterConfig = filterConfig;} // Process the request / response pair public void doFilter (ServletRequest request, ServletResponse response, filterChain filterChain) {try {request.setCharacterEncoding ( "GB2312"); ((HttpServletResponse) response) .setHeader ( "Cache-control", "no-cache"); response.setHeader ( "Pragma", "No -cache "); Response.setHeader (" cache-control "," no-cache "); response.setHeader (" Expires "," 0 "); (httpservletResponse) response) .SetHeader (" Pragram "," NO -cache "); filterChain.doFilter (request, response);} catch (ServletException sx) {filterConfig.getServletContext () log (sx.getMessage (.));} catch (IOException iox) {filterConfig.getServletContext () log. (Iox.getMessage ());}} // clean up resources public void design () {}} The following is a web.xml file You will generate a Xml version = "1.0" eNCoding = "ISO-8859-1" encoding = "ISO-8859-1" - // sun microsystems, Inc.//DTD Web Application 2.3 // en "" http://java.sun.com/dtd/web-app_2_3.dtd ">
3. I am using it now, recommend! !
Write a MyActionServlet and override the Process () method in the ActionServlet.
protected void process (HttpServletRequest request, HttpServletResponse response) throws java.io.IOException, javax.servlet.ServletException {/ ** @ todo Override this org.apache.struts.action.ActionServlet method * / request.setCharacterEncoding ( "GB2312") ; // add a line and do everything to solve super.process (Request, Response);
Of course, don't forget to change the configuration of Web.xml
Change the content in the servlet-class tag!
Really, one works Yi!
If the theory of specific encoding is not said, Google is already enough.
In addition, if you don't have Struts, Hibernate may also encounter Chinese garbled problems as long as it is in hibernate.cfg.xml configuration:
Characterencoding = GBK! Yes.