Solve the garbled problem of Struts1 processing received parameters inserted into the database

Source: Internet
Author: User

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"

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.