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.xm L 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:
. In the action class, this I tried, it's not workable.
In Actionform, I tried it, it worked, it was convenient.
Add the following code to the Reset method in Actionform, which can be exported in English or Chinese
View Sourceprint?
public void Reset (actionmapping mapping, HTTPS tutorial Ervletrequest request) {
try {
Request.setcharacterencoding ("GBK");
catch (Exception e) {
Todo:handle exception
}
}
Then you can output the attributes of Chinese in the action.
View Sourceprint?
Public Actionforward Execute (actionmapping mapping, Actionform form,
HttpServletRequest request, HttpServletResponse response) {
Personalform personalform = (personalform) form;//Todo auto-generated method stub
System.out.println (Personalform.getusername ());
System.out.println (Personalform.getpassword ());
Return Mapping.findforward ("Step2");
}