DZone Snippets is a public source code repository. Easily build up your personal collection of code snippets, categorize them with tags / keywords, and share them with the world

Oliver has posted 3 posts at DZone. View Full User Profile

Tomcat Encoding Test Page

07.14.2009
| 4689 views |
  • submit to reddit
        From: Oliver Paulus, http://blog.code-project.org

This is a Tomcat encoding test page. Tested with Tomcat 5.0, 5.5 and 6.0.

<%@ page 
  pageEncoding="utf-8" 
  language="java"
  contentType="text/html; charset=utf-8"
%>
<html>   
<head>
  <meta http-equiv="Content-Type" content="text/html; charset=utf-8">
</head>
<body>

<%
  /* uncomment next line to see that "setCharacterEncoding" call
     will not work anymore if any parameter read before */ 
  //String testParamBefore = request.getParameter("test");  

  request.setCharacterEncoding("utf-8"); 
  String test = request.getParameter("test");
  if (test != null) {
    out.write("the length of the test value after decoding: " + test.length());
  }
  out.write("<br>");
  out.write("the value of the test parameter: " + test);
  out.write("<br>");
%>

<form action="#" method="post">
  <input type="text" name="test" value="äöü">
  <input type="submit" value="test encoding!">
</form>

</body>
</html>