开发者

Servlets response.sendRedirect(String url) doesn't seems to send the encoding, why?

I have some Servlet that explicity sets the character encoding and redirect to some servlet

class Servlet1 extends HttpServle{
   void doGet(..... ){
        // ...
        request.setCharacterEncoding("UTF-8");
开发者_StackOverflow社区        response.setCharacterEncoding("UTF-8"):
        //......
        response.redirect(servlet2);
    }
}

class Servlet2 extends HttpServle{
   void doGet(..... ){
        // ...
        request.getCharacterEncoding();  // prints null ?? why???
        //......

    }
}

So, why the character encoding not being send with the request?


The HttpServletResponse#setCharacterEncoding() sets the encoding on the current response, not on the subsequent request. It's also not the client's responsibility to pass it back on the subsequent request. What you're trying to achieve is simply not possible without interaction of the client, which it is not required to do in this case. To get what you want, the client has to set the HTTP Content-Type header with a charset attribute itself. Check it with a HTTP header debugger tool like Firebug and you'll see that it is absent in the request.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜