• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Tim Cooke
  • Devaka Cooray
  • Ron McLeod
  • Jeanne Boyarsky
Sheriffs:
  • Liutauras Vilda
  • paul wheaton
  • Junilu Lacar
Saloon Keepers:
  • Tim Moores
  • Stephan van Hulst
  • Piet Souris
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Martijn Verburg
  • Frits Walraven
  • Himai Minh

Struts 1.3.10 encoding problem

 
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi ,
i am currently working on a struts application that needs to submit unicode charaters.

the unicode labels are displayed on the forms properly but whenever the user submits the form by typing unicode characters the values get garbled up.

I have tried the following options but to no help:
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"> (in jsp)
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%> (in jsp)


I have also tried to set the character encoding explicitly to utf-8 in the request and response objects using a flter.
And in tomcat i have also set the encoding to utf-8

One interesting thing that I found was that if i create a normal jsp page without using any struts tag and point to the same struts action the unicode characters are getting submitted properly.

I am assuming if this is any issue with the usage of the struts tag although i have specified the acceptCharset property in the html:form

Saikat
 
saikat mukherjee '
Greenhorn
Posts: 2
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Al last I found the solution by writing a filter



in web.xml
<filter>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>bt.gov.g2c.framework.common.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>requestEncoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>


<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>



The filter itself looks like:


public class CharacterEncodingFilter implements Filter {
private FilterConfig fc;

public void doFilter(ServletRequest req, ServletResponse res, FilterChain chain) throws IOException, ServletException {
HttpServletRequest request = (HttpServletRequest) req;
HttpServletResponse response = (HttpServletResponse) res;

request.setCharacterEncoding("UTF8");
response.setCharacterEncoding("UTF8");

chain.doFilter(request, response);

request.setCharacterEncoding("UTF8");
response.setCharacterEncoding("UTF8");

}
 
I think I'll just lie down here for a second. And ponder this tiny ad:
the value of filler advertising in 2021
https://coderanch.com/t/730886/filler-advertising
reply
    Bookmark Topic Watch Topic
  • New Topic