Konstantin,
On 4/1/21 05:06, Konstantin Kolinko wrote:
чт, 1 апр. 2021 г. в 00:55, Christopher Schultz <ch...@christopherschultz.net>:
[...]
I've written a tiny JSP to demonstrate the problem.
charecho.jsp
==== CUT ====
<%
response.setContentType("text/html");
response.setCharacterEncoding("UTF-8");
%><html>
<head>
<meta http-equiv="Content-Type" content="text/html; UTF-8" />
The value above is misspelled. You are missing "charset=" before "UTF-8".
Personally, I usually echo the actual contentType header value when
writing a meta tag. I think that would be
<meta http-equiv="Content-Type" content="<%= response.getContentType() %>">
Thanks for pointing that out. I have modified the charecho.jsp file, so
it is now:
<%@page contentType="text/html; charset=UTF-8" %>
<html>
<head>
<meta http-equiv="Content-Type" content="<%= response.getContentType()
%>" />
<meta charset="<%= response.getCharacterEncoding() %>" />
</head>
<body>
<form method="post" accept-charset="UTF-8">
<textarea name="text"><%= (null != request.getParameter("text") ?
request.getParameter("text") : "")%></textarea>
<input type="submit" />
</form>
</body>
</html>
The behavior is the same.
If I instead insert the following after the @page directive (to act as a
filter, to keep the example completely self-contained), then this works
as desired:
<%
if(null == request.getCharacterEncoding()) {
application.log("Character encoding is unset; setting to UTF-8");
request.setCharacterEncoding("UTF-8");
}
%>
[...]
So, somewhat "mystery solved" although I'd like to understand why
<request-character-encoding> didn't work.
Does validating your web.xml file against an xsd schema complete successfully?
request-character-encoding is defined in
(javax|jakarta)/serv/et/resources/web-app_4_0.xsd, which means Tomcat
9 or later. You wrote that you are running Tomcat 8.5.
Ooh, that would do it.
Confirmed: Using <request-character-encoding> with Tomcat *9* behaves as
desired, even without the filter/hack to correct a missing charset.
Thanks,
-chris
---------------------------------------------------------------------
To unsubscribe, e-mail: users-unsubscr...@tomcat.apache.org
For additional commands, e-mail: users-h...@tomcat.apache.org