Logo 
Search:

Java Forum

Ask Question   UnAnswered
Home » Forum » Java       RSS Feeds

Unicode Problem

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

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:

UNICODE

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?

Share: 

 

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)
Or
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;
request.setCharacterEncoding(targetEncoding);
chain.doFilter(srequest, sresponse);
}
}


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

<filter>
<filter-name>EncodingFilter</filter-name>
<filter-class>com.basamadco.opxi.manager.filter.EncodingFilter</filter-class>
</filter>

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

 
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.




Tagged: