LoginSignup
1
1

More than 5 years have passed since last update.

ブラウザに出力される日本語が文字化けするとき

Posted at

HttpServletResponse#setContentTypeをを設定すればよい。
Windows-31J、UTF-8はお好みで。

HelloServlet.java
public class HelloServlet extends HttpServlet {

    protected void doGet(HttpServletRequest request,
            HttpServletResponse response) throws ServletException, IOException {
        response.setContentType("text/html; charset=Windows-31J");
        PrintWriter pw = response.getWriter();
        pw.print("こんにちは世界");
    }
}
1
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
1
1