Reputation: 1
I am working in struts2.0 application with internationalization Apart from Chinese it working fine in other languages.
When I put Chinese character in jsp I am not getting same values in Action. Please help me for the same.
I have also used the UTF-8 pageEncoding
<%@page contentType="text/html" pageEncoding="UTF-8"%>
I have a text box in the jsp in which I'm filling some Chinese character.
But in the Action class on the server side when I try to retrieve the value of the text box,I'm getting junk characters.
I'm not able to add the screen shot as I don't have 10 reputations.
Any help will be appreciated.
Upvotes: 0
Views: 2209
Reputation: 81
Recently i faced an issue i.e. from jsp when I copy pasting a chinese character in name textbox and when i am trying to fetch that in Java DAO layer i get some junk value for name. With below code i have fixed the issue and i can get the chinese value same as in jsp.
String name = new String(entityObj.getName().getBytes("iso-8859-1"), "UTF-8");
Upvotes: 0
Reputation: 3833
In your action class before obtaining the parameters, set the request body encoding to the same encoding as the pageEncoding
of the JSP.
request.setCharacterEncoding("UTF-8");
Hope this helps!
P.S Above mentioned solution applies to POST
request only.
EDIT:
Get HttpServletRequest
in calling method of your action class:
HttpServletRequest request = ServletActionContext.getRequest();
and then set request
property as mentioned above.
EDIT2:
Add this line to your JSP
:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>
and add this filter
in your web.xml
:
<filter>
<filter-name>encodingFilter</filter-name>
<filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>forceEncoding</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>encodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
Upvotes: 1
Reputation: 6657
Try the following thing in your jsp
page
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
Upvotes: 0