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 ");
}