Logo 
Search:

Java Answers

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds
  Question Asked By: Kenneth Bennett   on Mar 31 In Java Category.

  
Question Answered By: Gorkem Yilmaz   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>

Share: 

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


Tagged: