Страница 1 из 1

[JAVA] XML encoding

Добавлено: 2011-07-22 10:49:54
iye
Приветствую!
Нет отдельной темы про джаву, почему напишу сюда. Есть следующий код:

Код: Выделить всё

		PrintWriter out = new PrintWriter(response.getOutputStream());
		// The servlet returns HTML.
		response.setContentType("text/html;charset=UTF-8");
		try {
			TransformerFactory tFactory = TransformerFactory.newInstance();
			// Get the XML input document and the stylesheet.
			Source xmlSource = new StreamSource((new SmbFile(_resDir, request.getParameter("tmpl"))).getInputStream());//    new URL("file:todo.xml").openStream());
			Source xslSource = new StreamSource(getClass().getResourceAsStream("tmpl.xsl"));
			// Generate the transformer.
			Transformer transformer = tFactory.newTransformer(xslSource);
                        transformer.setOutputProperty("encoding", "UTF-8");
			// Perform the transformation, sending the output to the response.
			transformer.transform(xmlSource, new StreamResult(out));
		} catch (Exception e) {
			out.write(e.getMessage());
			e.printStackTrace(out);
		}
Шаблон xsl и xml в кодировке windows-1251.
На юниксовом томкате все работает отлично. При переносе на виндовый томкат результирующий хтмл выводится в корявой кодировке. Вопрос - куда копать.

Re: [JAVA] XML encoding

Добавлено: 2011-07-22 10:51:17
iye
Пробовал перегнать шаблон в utf8 - ноль реакции.

Re: [JAVA] XML encoding

Добавлено: 2011-07-25 15:29:05
iye
Победил, использовав вместо PrintWriter OutputStreamWriter.