title: JSP Not Suppported by UTF-8 Encoding
body: <p>When I am trying to display Chinese characters in my JSP page, then it will display junk characters.</p>
  
  <p>What did I do wrong?</p>
  
  <p>I have included the below line to my JSP on the top, and even now, the issue is not getting fixed:</p>
  
  <pre><code>&lt;%@page contentType="text/html;charset=UTF-8" pageEncoding="UTF-8"%&gt;
  
  &lt;%@ page import="java.util.*"%&gt;
  &lt;%@ page import="com.hp.sales.om.workflow.c2c.config.model.Organization"%&gt;
  &lt;%@ page import="com.hp.sales.om.workflow.c2c.config.model.ClassificationL1"%&gt;
  &lt;%@ page import="com.hp.sales.om.workflow.c2c.config.model.ClassificationL2"%&gt;
  &lt;%@ page import="com.hp.sales.om.workflow.c2c.config.model.TaskConfig"%&gt;
  
   &lt;script type="text/javascript" language="javascript"
  src="/integration/r5/hpr/js/jquery-1.3.2.js"&gt;&lt;/script&gt;
  
  &lt;script language="JavaScript"&gt;
  //Javascript code here...
  &lt;/script&gt;
  
  &lt;%
  String taskId = (String) request.getAttribute("taskId");
  if (taskId == null || taskId.trim().equals("")) {
      taskId = ""; 
  %&gt;
  &lt;jsp:include page="/Header.jsp" /&gt;
  &lt;%@ taglib uri="http://xmlns.oracle.com/bpel/workflow/worklist-taglib.tld" prefix="worklist"%&gt;
  &lt;link rel="stylesheet" type="text/css" href="/integration/r5/hpr/css/homepages-v5.css" /&gt;
  &lt;%
  Map links = new LinkedHashMap();
      links.put("Select Task", request.getContextPath()
              + "/SelectTask");
      String disableCondition = "";
  %&gt;
  
  &lt;worklist:navLinks linkMap="&lt;%=links%&gt;" styleClass="customBreadCrumbNav"
  separator=" &gt; " prefixHTML="&lt;strong&gt;" suffixHTML="&lt;/strong&gt;"
  disableConditionBasedOn="&lt;%=disableCondition%&gt;" /&gt;
  &lt;!-- border table --&gt;
   &lt;TABLE WIDTH="100%" BORDER="0"&gt;
   &lt;TR&gt;
       &lt;TD&gt;
          &lt;TABLE WIDTH="100%" BORDER="1"&gt;
               &lt;TR&gt;
                          &lt;TD&gt;
                              &lt;%
                                  } else {
                               %&gt;
                      &lt;html&gt;
   &lt;head&gt;
   &lt;%@ page language="java" contentType="text/html; charset=UTF-8"
  pageEncoding="UTF-8"%&gt;
   &lt;META http-equiv="Content-Type" content="text/html; charset=UTF-8"&gt;
   &lt;title&gt;Select Task&lt;/title&gt;
   &lt;/head&gt;
   &lt;body&gt;
  &lt;%
      }
  %&gt;
  &lt;br /&gt;
  &lt;form STYLE="display: inline;" method="POST" name="SelectTask"
      action="&lt;%=request.getContextPath()%&gt;/SelectTask"&gt;
  
      &lt;input type="hidden" name="method" id="method" value='' /&gt; &lt;input
          type="hidden" name="method" id="method" value='' /&gt; &lt;input
          type="hidden" name="taskId" id="taskId" value='&lt;%=taskId%&gt;' /&gt;
  
      &lt;!-- jQuery Ajax stuff for new way of create task, page not be refresh when choose organization --&gt;
      &lt;script type="text/javascript"&gt;
       var servletContextPath = &lt;%=request.getContextPath()%&gt;
          ";"
          $(document)
                  .ready(
                          function() {
  
                              $(window).load(function() {
                                                  $.ajax({
                                                              url : servletContextPath
                                                                      + "/OrganizationLoadServlet",
                                                              cache : false,
                                                              beforeSend : function() {
                                                                  //alert(this.url == 'myUrl');
                                                                  //timeout setting 30second
                                                                  ajax_timeout = setTimeout(
                                                                          function() {
                                                                              //alert('Request is taking a long time.');
                                                                                                              },
                                                                          30000);
                                                                  //
                                                              },
                                                              success : function(
                                                                      xmlResponse) {
                                                                  var count = 0;
                                                                  $(xmlResponse)
                                                                          .find('ITEMS')
                                                                          .each(function() {
                                                                                      count++;
                                                                                  });
                                                                  if (count == 1) {
                                                                      $(xmlResponse).find('ITEMS')
                                                                              .each(function() {
                                                                                                                                  });
                                                                      $.ajax({
                                                                                  type : "GET",
                                                                                  url : servletContextPath
                                                                                          + "/OrganizationProcessHandler",
                                                                                  data : {
                                                                                      orgId : $params
                                                                                  },
                                                                                  cache : false,
                                                                                  beforeSend : function() {
                                                                                      ajax_timeout2 = setTimeout(
                                                                                              function() {
                                                  },
                                                                                              30000);
                                                                                  },
                                                                                  success : function(xmlResponse) {
                                          $(xmlResponse).find('ITEMS')
                                                                                              .each(function() {
                                                          });
                                                                                      //timeout calling
                                                                                      if (ajax_timeout2) {
                                                                                          clearTimeout(ajax_timeout2);
                                                                                      }
                                                                                  }
                                                                              });
  
                                                                  } else {
                                                                      $(xmlResponse).find('ITEMS')
                                                                              .each(function() {
                                                                                      });
                                                                  }
                                                                  //timeout calling
                                                                  if (ajax_timeout) {
                                                                      clearTimeout(ajax_timeout);
                                                                  }
                                                                  //
                                                              },
                                                              complete : function() {
                                                                  //alert(this.async == true);
                                                              }
                                                          });
  
                                              });
  
                              //Business Process choicebox
                              $("#orgId").change(function() {
                                                  $.ajax({
                                                              type : "GET",
                                                              url : servletContextPath
                                                                      + "/OrganizationProcessHandler",
                                                              data : {
                                                                  orgId : $params
                                                              },
                                                              cache : false,
                                                              beforeSend : function() {
                                                                  //alert(this.url == 'myUrl');
                      //timeout setting 30second
                                                                  ajax_timeout = setTimeout(
                                                                          function() {
                                                                              //alert('Request is taking a long time.');
                              },
                                                                          30000);
                                                                  //
                                                              },
                                                              success : function(xmlResponse) {
                                                                  $(xmlResponse).find('ITEMS')
                                                                          .each(function() {
                                                                                                                                                                          });
                                                                  //timeout calling
                                                                  if (ajax_timeout) {
                                                                      clearTimeout(ajax_timeout);
                                                                  }
                                                                  //
                                                              },
                                                              complete : function() {
                                                                  //alert(this.async == true);
                                                              }
                                                          });
  
                                              });
  
                              //Task Group handler
                              $("#processId").change(function() {
                                                  if ($processId.length != 0) {
                                                      $.ajax({
                                                                  type : "POST",
                                                                  url : servletContextPath
                                                                          + "/TaskGroupsForOrgAndProcessHandler",
                                                                  data : {
                                                                      orgId : $orgId,
                                                                      processId : $processId
                                                                  },
                                                                  cache : false,
                                                                  beforeSend : function() {
                                                                      //alert(this.url == 'myUrl');
                          //timeout setting 30second
                                                                      ajax_timeout = setTimeout(
                                                                              function() {
                                                                                  //alert('Request is taking a long time.');
                                                                              },
                                                                              30000);
                                                                      //
                                                                  },
                                                                  success : function(xmlResponse) {
                                                                      $(xmlResponse).find('ITEMS')
                                                                              .each(function() {
                                                                                          //alert("Task Group === "+valTxt);
                                                                                          $('&lt;option value="' + valTxt + '"&gt;'
                                                                                                          + labelTxt
                                                                                                          + '&lt;/option&gt;')
                                                                                                  .appendTo("#taskGrpId");
                                                                                      });
                                                                      //timeout calling
                                                                      if (ajax_timeout) {
                                                                          clearTimeout(ajax_timeout);
                                                                      }
                                                                      //
  
                                                                  },
                                                                  complete : function() {
                                                                      //alert(this.async == true);
                                                                  }
                                                              });
                                                  }
                                              });
  
                              //Task handler
                              $("#taskGrpId").change(function() {
                                                  if ($taskGrpId.length != 0) {
                                                      $.ajax({
                                                                  type : "POST",
                                                                  url : servletContextPath
                                                                          + "/TaskConfigsHandler",
                                                                  data : {
                                                                      orgId : $orgId,
                                                                      processId : $processId,
                                                                      taskGrpId : $taskGrpId
                                                                  },
                                                                  cache : false,
                                                                  beforeSend : function() {
                                                                      ajax_timeout = setTimeout(
                                                                              function() {
                                                                                  //alert('Request is taking a long time.');
                                                                              },
                                                                              30000);
                                                                      //
                                                                  },
                                                                  success : function(
                                                                          xmlResponse) {
                          $(xmlResponse).find('ITEMS')
                                                                              .each(function() {
                                                                                                                                                                              });
                                                                      //timeout calling
                                                                      if (ajax_timeout) {
                                                                          clearTimeout(ajax_timeout);
                                                                      }
                                                                      //
  
                                                                  },
                                                                  complete : function() {
                                                                      //alert(this.async == true);
                                                                  }
                                                              });
                                                  }
                                              });
  
                          });
      &lt;/script&gt;
      &lt;!-- endless --&gt;
  
      &lt;!-- Layer for during do submition --&gt;
      &lt;script type="text/javascript"&gt;
          $(document)
                  .ready(
                          function() {
                              $("#Save").click(
                                              function() {
                                                  var taskConfigId = document
                                                          .getElementById("taskConfigId").value;
                                                  if (taskConfigId == null
                                                          || taskConfigId == ''
                                                          || taskConfigId == -4
                                                          || taskConfigId.length == 0) {
                                                      alert('Please select task');
                                                  } else {
                                                      getBackToTaskCreationForm();
                                                      //Get the screen height and width
                                                      var maskHeight = $(document).height();
                                                      var maskWidth = $(window).width();
  
                                                      //alert("taskConfigId== " +taskConfigId);
                                                      //Set heigth and width to mask to fill up the whole screen
                                                      $('#mask').css({
                                                                          'width' : maskWidth,
                                                                          'height' : maskHeight
                                                                      });
  
                                                      //transition effect     
                                                                                              }
                                              });
  
                          });
      &lt;/script&gt;
  
      &lt;style&gt;
  </code></pre>
  
  <p>The code continues below:</p>
  
  <p></p>
  
  <pre><code>    &lt;!-- endless --&gt;
  
      &lt;table width="100%" border="0" class="HeaderPane" cellpadding=0
          cellspacing=0 height="44" bordercolor="#000000"&gt;
          &lt;tr width="100%"&gt;
              &lt;td width="100%" class="customContentText"&gt;&lt;strong&gt;Organization:&lt;/strong&gt;
                  &lt;select id="orgId" name="orgId"&gt;
                      &lt;option VALUE='-1'&gt;------------ Select Organization
                          ------------&lt;/option&gt;
              &lt;/select&gt;&lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr width="100%"&gt;
              &lt;td width="100%" class="customContentText"&gt;
                  &lt;p id="loading" style="margin-left: 80px;"&gt;
                      &lt;img src="/integration/r5/hpr/images/ajax-loader.gif"
                          alt="loading" /&gt; &lt;br /&gt;Please wait....
                  &lt;/p&gt;
                  &lt;p id="done"&gt;&lt;/p&gt;
  
  
                  &lt;p id="warning" style="margin-left: 80px;"&gt;
                      &lt;img src="img/warnsign.gif" alt="warning" width="16" height="16" /&gt;
                      &lt;br /&gt;Your request has timed out. Please try again. If this
                      condition continues, please contact your administrator.
                  &lt;/p&gt;  &lt;br /&gt;
              &lt;/td&gt;
          &lt;/tr&gt;
          &lt;tr width="100%"&gt;
              &lt;td width="100%" class="customContentText"&gt;
                  &lt;table width="100%" align="center" class="HeaderPane" id="table1"&gt;
                      -------
                  &lt;/table&gt;
              &lt;/td&gt;
              &lt;/form&gt;
      &lt;/table&gt;
  
      &lt;!-- Mask to cover the whole screen --&gt;
      &lt;div id="mask"&gt;
          &lt;center&gt;
              &lt;img src="/integration/r5/hpr/images/ajax-loader.gif" alt="loading" /&gt;
              &lt;br /&gt;
              &lt;font color="White" size="4"&gt; Please wait....&lt;/font&gt;
          &lt;/center&gt;
      &lt;/div&gt;
  
  
      &lt;%
          if (taskId == null || taskId.trim().equals("")) {
      %&gt;
  
                  &lt;/TD&gt;
              &lt;/TR&gt;
          &lt;/TABLE&gt;
      &lt;/TD&gt;
  &lt;/TR&gt;
  &lt;/TABLE&gt;
  &lt;jsp:include page="/Footer.jsp" /&gt;
  &lt;%
          } else {
  %&gt;
  &lt;/body&gt;
  &lt;/html&gt;
  &lt;%
          }
  %&gt;
  </code></pre>
  
  <p>Here's my web.xml file:</p>
  
  <pre><code>&lt;?xml version = '1.0' encoding = 'GBK'?&gt;
  &lt;web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
       xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns  /javaee/web-app_2_5.xsd"
       version="2.5" xmlns="http://java.sun.com/xml/ns/javaee"&gt;
  
  &lt;/web-app&gt;
  </code></pre>
  
  <p>Servlet:</p>
  
  <pre><code>public class OrganizationLoadServlet extends HttpServlet {
      private static Logger log = Logger.getLogger(OrganizationLoadServlet.class);
  
      public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          HttpSession session = request.getSession();
  
          Organization[] orgs = (Organization[])session.getAttribute(WorklistappConstants.SESS_ATTR_PREFS_ORGANIZATIONS);
  
          if (orgs == null) {
              orgs = getFilteredOrgs(request);
              session.setAttribute(WorklistappConstants.SESS_ATTR_PREFS_ORGANIZATIONS, orgs);
          }
  
          log.info("Before: " + response.getCharacterEncoding());//Here I am getting "iso-8859-1"
          StringBuffer sb = new StringBuffer();
          String dislayName = null;
          for (int i = 0; i &lt; orgs.length; i++) {
              Organization org = orgs[i];
              dislayName = org.getOrgDisplayName();
  
              sb.append("&lt;ITEMS&gt;");
              sb.append("&lt;LABEL&gt;&lt;![CDATA[" + dislayName + "]]&gt;&lt;/LABEL&gt;");
              sb.append("&lt;VALUE&gt;&lt;![CDATA[" + org.getOrgId() + "]]&gt;&lt;/VALUE&gt;");
              sb.append("&lt;/ITEMS&gt;");
          }
  
          response.setContentType("text/xml");
          response.setHeader("Cache-Control", "no-cache");
          response.getWriter().write("&lt;?xml version=\"1.0\" encoding=\"iso-8859-1\"?&gt;&lt;ITEM&gt;" + sb.toString() + "&lt;/ITEM&gt;");
          log.info("After: " + response.getCharacterEncoding());//Here I am getting "iso-8859-1"
  
      }
  
      public void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
          this.doGet(request, response);
      }
  
      private Organization[] getFilteredOrgs(HttpServletRequest request) {
      //code
      return orgs;
  
      }
  
      private Organization[] filterOrganizationsByUserOrgs(Organization[] orgs, List&lt;Long&gt; userOrgIdList) {
          //code
  
          return filteredOrgs;
      }
  
      private List&lt;Long&gt; getUserOrgIdList(String userId) throws Exception {
      //code
  
          return userOrgIdList;
      }
  
      private String getUserID(HttpServletRequest request) throws IOException {
  
      //code
          return wfCtx.getUser();
      }
  
  }
  </code></pre>
  
  <p>Please see the comments in the Servlet class. If I change <code>iso-8859-1</code> to <code>utf-8</code>, then I am not able to access the application.</p>
  
  <p>Why is this issue occurring?</p>