Only 44 hours left in the trailboss' kickstarter!

New rewards and stretch goals. CLICK HERE!



  • Post Reply Bookmark Topic Watch Topic
  • New Topic

Character set problems  RSS feed

 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have just moved my applications to a web hotel in USA, running on Tomcat Server. The scandinavian characters, '�', '�' and '�' is shown as a '?'. It only happens, when I post the characters with enctype="multipart/form-data" or when I want to store data in a file and read from a file.

The scandinavian characters, '�', '�' and '�' is stored and shown correct when typed it in the ordinary textfiels and textareas, which is posted and saved to the database.

How can I solve the character problems in enctype="multipart/form-data" and files handling? Is it a setting in my web application (jsp/servlet charset setting) or does it have to be a setting changed in the Apache Tomcat environment?
 
D Rog
Ranch Hand
Posts: 472
Linux Objective C Ubuntu
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
http://www.faqs.org/rfcs/rfc2388.html
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Make sure that you use the same character encoding everywhere, e.g. UTF-8. That goes for reading/writing files, storing text in the DB, reading web forms and writing web pages.
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Then can I just write the following code in my jsp files:

<%@ page language="java" contentType="text/html; charset=UTF-8" %>

What about ???:
<%
request.setCharacterEncoding("UTF-8");
%>

and in my servlets:
...
res.setContentType("text/plain; charset=UTF-8");
...

Will that solve the problem, in case that I choose the right charset code?
[ July 29, 2005: Message edited by: Jeppe Fjord ]
 
Ulf Dittmer
Rancher
Posts: 42970
73
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You'd need the first and third to write your web pages, and the second for reading the submitted form input.

If the user is running the standard JDK on a US locale, the standard file encoding might be US-ASCII (not sure about that). So in your writing to and reading from files you need to specify that you want UTF-8 encoding instead.

As to the DB, that may have to be set during DB creation time; at least PostgreSQL does it that way, I don't know about others.
[ July 29, 2005: Message edited by: Ulf Dittmer ]
 
Jeppe Sommer
Ranch Hand
Posts: 270
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks guys. To anyone having the same problem, it works with:

Jsp files:
<%@page pageEncoding="iso-8859-1" contentType="text/html; charset=UTF-8" %>

Servlets:
response.setContentType("text/html; charset=UTF-8");
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!