tomcat-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Rashmi Rubdi" <rashmi....@gmail.com>
Subject Re: charset encoding bug
Date Tue, 24 Apr 2007 20:19:59 GMT
Hi Sean,

You are right with the fact that the character set encoding does get
appended to the Content-Type header when the Locale is set.

However, according to the API docs:
http://java.sun.com/javaee/5/docs/api/javax/servlet/ServletResponse.html#setLocale(java.util.Locale)

"........ It also sets the response's character encoding appropriately
for the locale, if the character encoding has not been explicitly set
using setContentType(java.lang.String) or
setCharacterEncoding(java.lang.String), getWriter hasn't been called
yet, and the response hasn't been committed yet. If the deployment
descriptor contains a locale-encoding-mapping-list element, and that
element provides a mapping for the given locale, that mapping is used.
Otherwise, the mapping from locale to character encoding is container
dependent............."

So the above is expected behavior and not considered a bug, because
Tomcat 5.5.23 complies with Servlet 2.4 specification which is defined
in the JavaEE5 API.

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~
Here's the code I just tried:

package test81;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpServlet;
import javax.servlet.ServletException;
import javax.servlet.RequestDispatcher;
import java.io.IOException;
import java.util.Locale;

public class ContentTypeServlet extends HttpServlet {
    public void doGet(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
        processRequest(request, response);
    }

    public void doPost(HttpServletRequest request, HttpServletResponse
response) throws IOException, ServletException {
        processRequest(request, response);

    }

    private void processRequest(HttpServletRequest request,
HttpServletResponse response) throws IOException, ServletException {
        response.setContentType("application/xml");
        response.setLocale(Locale.US);

        RequestDispatcher rd =
getServletContext().getRequestDispatcher("/p/test81/test81.jsp");
        rd.forward(request,response);

        //response.sendRedirect("/p/test81/test81.jsp");
    }
}

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

<%@ page contentType="application/xml" language="java" %>
<html>
  <head><title></title></head>
  <body>
  Get Content type:
  <%=response.getContentType()%>
  </body>
</html>
-Regards
Rashmi

~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~

Output:

−
	<html>
−
	<head>
<title/>
</head>
−
	<body>
  Get Content type:
  application/xml;charset=ISO-8859-1

</body>
</html>

-Regards
Rashmi

---------------------------------------------------------------------
To start a new topic, e-mail: users@tomcat.apache.org
To unsubscribe, e-mail: users-unsubscribe@tomcat.apache.org
For additional commands, e-mail: users-help@tomcat.apache.org


Mime
View raw message