Solution of Actionform Chinese garbled problem in JSP

Source: Internet
Author: User

Actionform Chinese garbled problem solving method in JSP tutorial

Let's take a look at actionform.

Actionform concept
Actionform is used to encapsulate the user's request parameters, and request parameters are passed through the form fields of the JSP page. You should therefore ensure that the actionform parameters are the same as the name of the form field.
Edit this section actionform configuration
All Actionform are configured in the Struts-config.xml file, which includes a Form-beans element that defines all actionform, each actionform corresponding to a form-bean element.

The JSP page receives the Actionform the attribute, if the input is the Chinese, then after Actionform receives will be garbled

The solution has 2:

1. Solve in the action class, this I tried, not feasible

2. Solve in the actionform, this I tried, feasible, and very convenient

Add the following code to the Reset method in Actionform, which can be exported in English or Chinese

View sourceprint?1 public void Reset (actionmapping mapping, HTTPS tutorial Ervletrequest request) {

2 try {

3 request.setcharacterencoding ("GBK");

4} catch (Exception e) {

5//Todo:handle exception



Then you can output the attributes of Chinese in the action.

View sourceprint?1 public Actionforward execute (actionmapping mapping, Actionform form, 

2              HttpServletRequest Request, HttpServletResponse response) { 


4         personalform personalform = (personalform) form;//todo Auto-generated method stub 

5         System.out.println ( Personalform.getusername ());  

6         System.out.println ( Personalform.getpassword ())  

7         return Mapping.findforward ("Step2");  

8    }

Related Article

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: 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.