0

In the context of a Wicket component using JavaScript, I'm sending the following string back to Wicket :

"FICHIERfichier&é'(-è_çà)=~#{[`^@]}^$ù,;!¨£%µ§êë-+¤.0²123456789.pdf"

I have to escape() this in JavaScript because otherwise Wicket interprets the ampersand as a parameter delimiter and chops the string into multiple parameters.

However, this is what I get on the Wicket side of things :

"FICHIERfichier&�'(-�_��)=~#{[`^@]}^$�,;!��%����- �.0�123456789.pdf"

Any ideas ? I've tried many unescape/decode methods to no avail...

Many Thanks !

Defenestrate
  • 433
  • 2
  • 6
  • 14

1 Answers1

0

It seems the character encoding your application uses does not support some of the sent characters.

Make sure you use a good charset in Wicket's RequestCycleSettings. By default it is UTF-8, but your application may have changed it.

In addition if you use some old version of a Servlet container then you may need to use a Servlet Filter around Wicket Filter that sets the character encoding on the HttpServletRequest. A quick googling for "Servlet filter character encoding" gives this good example: https://stackoverflow.com/a/11100412/497381.

public class CustomCharacterEncodingFilter implements Filter {

  public void init(FilterConfig config) throws ServletException {
  }

  public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) 
                                                   throws IOException, ServletException {
    request.setCharacterEncoding("UTF-8");
    response.setCharacterEncoding("UTF-8");
    chain.doFilter(request, response);
  }

  public void destroy() {
  }

}
martin-g
  • 17,243
  • 2
  • 23
  • 35