Struts solves the problem of receiving parameter garbled characters (parameters accepted by actionForm are sent to the database with garbled characters:
Step 1: Create a class, for example, EncodingActionServlet inherits the ActionServlet and overwrites the process () method of the parent class. The Code is as follows:
Package com. aptech. jb. epet. web. action;
Public class EncodingActionServlet extends ActionServlet {
Public void process (HttpServletRequest request,
HttpServletResponse response)
Throws ServletException, IOException {
Request. setCharacterEncoding ("GBK"); // handle garbled characters
Super. process (request, response); // call the parent class Method
}
}
Step 2, modify WEB-INF/web. xml configuration:
<Servlet>
<Servlet-name> action </servlet-name>
<Servlet-class> com. aptech. jb. epet. web. action. EncodingActionServlet </servlet-class>
</Servlet>
// Other code is omitted, that is, to change the original ActionServlet to a subclass of the custom ActionServlet
Step 3: Save and restart the tomcat server. No garbled characters will appear during database insertion (the jsp page code is also "GBK!
Note: I am not very clear about any defects in this method. If you are a senior expert, please advise me more! Thank you!
Author "loading"