How to solve Chinese garbled characters in ActionForm in jsp

Source: Internet
Author: User

How to solve Chinese garbled characters in ActionForm in jsp

How to solve the Chinese garbled problem of actionform in jsp tutorial

Let's take a look at actionform.

Actionform Concept

Actionform is used to encapsulate the user's request parameters, and the request parameters are passed through the form fields on the jsp page. Therefore, ensure that the actionform parameter is the same as the form field name.

Edit actionform configurations in this section

All actionforms are configured in the struts-config.xm l file, which includes an element of form-beans that defines all actionforms and each actionform corresponds to a form-bean element.

When the jsp page receives the actionform attribute, if the input is Chinese, it will be garbled after the actionform receives

There are two solutions:

. Solved in the action class. I tried this and it is not feasible.

. Solve this problem in actionform. I have tried it and it is feasible and convenient.

Add the following code to the reset method in actionform to output English or Chinese characters.

View sourceprint?

Public void reset (actionmapping mapping, https tutorial ervletrequest request ){

Try {

Request. setcharacterencoding ("gbk ");

} Catch (exception e ){

// Todo: handle exception

}

}

Then, the Chinese attributes can be output in the action.

View sourceprint?

Public actionforward execute (actionmapping mapping, actionform form,

Httpservletrequest request, httpservletresponse response ){

Personalform = (personalform) form; // todo auto-generated method stub

System. out. println (personalform. getusername ());

System. out. println (personalform. getpassword ());

Return mapping. findforward ("step2 ");

}

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