"Christmas - the time to fix the computers of your loved ones" « Lord Wyrm

[JAVA] Problem mit Encoding

tinker 04.08.2010 - 14:47 1274 5
Posts

tinker

SQUEAK
Avatar
Registered: Nov 2005
Location: NÖ
Posts: 5219
Folgende Sache:
Alt: Oracle 9 mit ISO-8859-15 und in den JSPs charset und pageEncoding auf ISO-8859-1

Jetzt wurde auf Oracle 10 mit utf-8 gewechselt. Wenn ich jetzt die JSPs auf ISO-8859-1 lasse, werden umlaute, soweit ich seh, richtig in die DB geschrieben. Nur statt dem €-Zeichen steht ein Kästchen.

Ok, also mal in den JSPs auf utf-8 gewechselt. Jetzt hab ich auf Java-Seite das Problem, dass Umlaute und das €-Zeichen wirr codiert werden und auch so in die DB kommen. Aber keine Ahnung wo ich da noch was angreifen muss...

Wie gesagt, bisher nur mal die JSPs auf utf-8 geändert.


Umgebung: Win, Java 1.6, Tomcat 5.5, Struts 1.2.9, Spring 2.5.6

tia
Bearbeitet von tinker am 04.08.2010, 15:23

Nico

former person of interest
Registered: Sep 2006
Location: -
Posts: 4082
was hast du denn geändert in den jsp?

tinker

SQUEAK
Avatar
Registered: Nov 2005
Location: NÖ
Posts: 5219
Code:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1" pageEncoding="ISO-8859-1"%>
auf
Code:
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%>

Nico

former person of interest
Registered: Sep 2006
Location: -
Posts: 4082

Punisher

Bukanier
Avatar
Registered: Sep 2002
Location: Disneyland
Posts: 1865
nicht nur im tomcat

Zitat
What can you recommend to just make everything work? (How to use UTF-8 everywhere).

Using UTF-8 as your character encoding for everything is a safe bet. This should work for pretty much every situation.

In order to completely switch to using UTF-8, you need to make the following changes:

1.

Set URIEncoding="UTF-8" on your <Connector> in server.xml. References: HTTP Connector, AJP Connector.
2.

Use a character encoding filter with the default encoding set to UTF-8
3. Change all your JSPs to include charset name in their contentType.

For example, use <%@page contentType="text/html; charset=UTF-8" %> for the usual JSP pages and <jsp:directive.page contentType="text/html; charset=UTF-8" /> for the pages in XML syntax (aka JSP Documents).
4. Change all your servlets to set the content type for responses and to include charset name in the content type to be UTF-8.

Use response.setContentType("text/html; charset=UTF-8") or response.setCharacterEncoding("UTF-8").
5. Change any content-generation libraries you use (Velocity, Freemarker, etc.) to use UTF-8 and to specify UTF-8 in the content type of the responses that they generate.
6.

Disable any valves or filters that may read request parameters before your character encoding filter or jsp page has a chance to set the encoding to UTF-8. For more information see http://www.mail-archive.com/users@t.../msg21117.html.

http://wiki.apache.org/tomcat/FAQ/CharacterEncoding

tinker

SQUEAK
Avatar
Registered: Nov 2005
Location: NÖ
Posts: 5219
Zitat von Nico
lies mal das
http://stackoverflow.com/questions/...in-java-webapps
thx, der filter wars!
Kontakt | Unser Forum | Über overclockers.at | Impressum | Datenschutz