Unicode converting 2 times....please help me...some what urgent
Hi all
Thank you every one ....for giving me a temendous support to solving my problems..
here iam strucked out with a small problem
Here it goes
Iam doing a chinese project in struts hibernate and spring
In this iam getting some data from database(mysql) data is in the for of unicode..
Let assume iam getting profile info of a person from database ..which is in the form of unicode..iam trying to display this information on a jsp...and i sucessfully did this
For this iam adding this directive to jsp
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="UTF-8"%>
So it is displaying properly
But the problem starts here
When iam edit this page and sends the data is converting to unicode in the action and when iam storeing it in to database , The database again converting it to unicode ...so this is my problem ...because of this iam getting some junk characters in the jsp...please
i hope you people help me in this issue
this is some what urgent for me ...iam strucked here from last 2 days
Please give me some suggestion how can i solve this problem ...your ideas are most appriciated
If question is not clear please let me know as soon as possible i will try to clear it
Thank you
Srikanth
# 2
Hi
we have solved this problem
When most of the programmers are raises this problem when coverting unicode to chinese characters
But we can solve this problem by using filer class:
Here is the filter class:
Step 1:
public class CharsetFilter implements Filter {
public void init(FilterConfig filterConfig) throws ServletException {
//To change body of implemented methods use File | Settings | File Templates.
}
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException
{
request.setCharacterEncoding("UTF-8");
chain.doFilter(request,response);
}
public void destroy() {
//To change body of implemented methods use File | Settings | File Templates.
}
}
Step 2:
Add the following entry in web.xml
<filter>
<filter-name>Character Encoding</filter-name>
<filter-class>com.web.common.CharsetFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>Character Encoding</filter-name>
<servlet-name>action</servlet-name>
</filter-mapping>
step 3:
add a page directive in corresponding jsp page which will dispaly the chinese character and a meta tag in head section
The two tags here:
page directive:
<%@ page contentType="text/html; charset=utf-8" %>
<%@ page pageEncoding="UTF-8"%>
meta tag:
<META http-equiv=Content-Type content="text/html; charset=utf-8">
I hope its will help you ...if not please let me know.
Regards
Srikanth