Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Unicode Problem

  Asked By: Ayden    Date: Nov 11    Category: Java    Views: 718

I have a j2ee application that works fine in Linux and Tomcat.
Now i have to run it on a Wind*ws Server 2003 machine.
I'd copied everything needed into win box.
Every thing works fine except one thing:


I tested the system encoding with System.getProperty("file.encoding") on both machines
and got UTF8 on Linux and Cp1252 on Wind*ws.

I know that this property can be changed by setProperty("file.encoding", "UTF8"). but
this works only for that run of the application and I should add it to all of my codes. ( Poof, what a boring task)

As an other option, I can run java with -Dfile.encoding=UTF8 option.

How can I tell tomcat to do that?
Or is there an other way?



2 Answers Found

Answer #1    Answered By: Sonya Flores     Answered On: Nov 11

In this case you could save your pages as utf-8 unicode  (Codepage)
Using Filtering Pattern to do this in all across your project
I write this for you to use it and joy it.

public class EncodingFilter implements Filter {

private final String targetEncoding = "UTF-8";

public void init(FilterConfig config) throws ServletException {

public void destroy() {

public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain chain)
throws IOException, ServletException {

HttpServletRequest request = (HttpServletRequest) srequest;
chain.doFilter(srequest, sresponse);

and then you should declare this line in web.xml of your project


<url-pattern>*.htm</url-pattern> <!-- your pages extentions like html or jsp or jsf and so on-->

Answer #2    Answered By: Eric Foster     Answered On: Nov 11

You can set JAVA_OPTIONS in tomcat/bin/startup.bat .

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