Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Struts and Farsi Language

  Asked By: Kenneth    Date: Mar 31    Category: Java    Views: 1376
  

i write a multilingual project
with(Struts&MySql&Jboss)
but , i have problem with farsi language...
i coded this line in the my JSP pages...
1-<%@ page contentType="text/html;charset=UTF-8"
language="java" %>
2- request.setCharacterEncoding("utf-8");
3-<meta http-equiv="Content-Type" content="text/html;
charset=utf-8">

and :
in Jboss i set the URIENCODING to UTF_8

and my data in(MySql)is correct! but farsi carachters
is Wrong(in jsp pages)!?

i solve this problem by chnage my data format from
ISO-.. to UTF8 when i want save this data to
database.. but i think this sloution it is not good...
please help me that i find a good sloution for this problem..

Share: 

 

1 Answer Found

 
Answer #1    Answered By: Gorkem Yilmaz     Answered On: Mar 31

You must define an encoding filter to process and set  encoding of
request's content.


public class RequestEncodingFilter implements Filter{

private String encoding;

public void init(FilterConfig config) throws ServletException {
encoding = "UTF-8";
String enc = config.getInitParameter("encoding");
if(enc !=null && enc.length() > 0){
encoding = enc;
}
}

public void destroy() {}

/**
* <p>Dispatching specified request  changing its parameter's
character
* encoding. Struts applications generate pages  in utf-8. Then
request
* parameter of normal PC browser is in utf-8. That's why this
filter
* handles it in utf-8. If some user agent works on different
encoding,
* character encoding can be specified in web.xml, filter element.
* </p>
*/
public void doFilter(ServletRequest request,
ServletResponse response,
FilterChain chain)
throws IOException, ServletException {

request.setCharacterEncoding(encoding);
chain.doFilter(request, response);
}
}

and then define it in web.xml

!-- Encoding Filter Configuration -->
<filter>
<filter-name>requestEncodingFilter</filter-name>
<filter-class>RequestEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>

 
Didn't find what you were looking for? Find more on Struts and Farsi Language Or get search suggestion and latest updates.




Tagged: