Browse Source

Merge pull request #1193 from TechEmpower/fixServlet

Fix servlet
Mike Smith 10 years ago
parent
commit
6fe16cf6e0
1 changed files with 4 additions and 1 deletions
  1. 4 1
      frameworks/Java/servlet/src/main/java/hello/FortunesServlet.java

+ 4 - 1
frameworks/Java/servlet/src/main/java/hello/FortunesServlet.java

@@ -19,6 +19,8 @@ public class FortunesServlet extends HttpServlet
   
   // Database details.
   private static final String DB_QUERY = "SELECT * FROM Fortune";
+  private static final String UTF8 = "UTF-8";
+  private static final String CONTENT_TYPE_HTML_UTF8 = "text/html;charset=UTF-8";
 
   // Database connection pool.
   @Resource(name="jdbc/hello_world")
@@ -29,7 +31,8 @@ public class FortunesServlet extends HttpServlet
       throws ServletException, IOException
   {
     // Set content type to JSON
-    res.setHeader(Common.HEADER_CONTENT_TYPE, Common.CONTENT_TYPE_HTML);
+    res.setCharacterEncoding(UTF8);
+    res.setContentType(CONTENT_TYPE_HTML_UTF8);
 
     final List<Fortune> fortunes = new ArrayList<>();