Pergunta

I have a jsp page running under jboss 4.2.2 server.

The structure for the page is something like this:

include head ( head is written on another page, like masterpage in aspx. )
(body ( where the problem appears ))
include foot ( foot is also written in another page. )

The head page contains the encoding and meta tags:

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">

When I write characters in the page such as şğĞİÇçÖ (Turkish) the characters are shown as "?" ( question mark ) what should I do to avoid this behavior?

How can I have the text shown just as writen in the jsp page?

Foi útil?

Solução

I see two potential causes:

  1. Your editor didn't save the page as UTF-8. Check the default settings and/or the Save As option.
  2. The @page is missing in some of the JSPs. It has to be present in all JSP files, also the includes.

Unrelated to the concrete problem, the following in top of JSP was been enough:

<%@ page pageEncoding="UTF-8" %>

The remnant which you've put there are already (implicit) defaults.

Outras dicas

In addition to the DOCTYPE declaration it is usually a good idea to include a meta tag in the document <head> like this:

<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />

Beyond that BalusC's suggestion that all files involved need to be actually SAVED with UTF8 encoding is very important.

Add this snippet into your servlet:

request.setCharacterEncoding("UTF-8");

response.setContentType("text/html; charset=utf-8");
Licenciado em: CC-BY-SA com atribuição
Não afiliado a StackOverflow
scroll top