title: Embedded Jetty NotUtf8Exception
body: <p>We are running a web application embedded in a jetty container. On a jsp there is a jsp:forward. The values of the jsp:param are <code>ISO-8859-1</code>. How can I tell Jetty, that the URL is ISO-8859-1?</p>
  
  <p>The system property <code>org.eclipse.jetty.util.UrlEncoding.charset</code> is not working. <code>org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! incomplete UTF8 sequence...</code> is thrown.</p>
  
  <p>Here is an example of the jsp:</p>
  
  <pre><code>&lt;%@ page language="java" pageEncoding="ISO-8859-1" %&gt;
  ...
  &lt;jsp:forward page="/forwardToAServlet"&gt;
  &lt;jsp:param name="param1" value="an+example+with+an+umlaut+gr%F6%DFere" /&gt;
  &lt;/jsp:forward&gt;
  </code></pre>
  
  <p>And here the stacktrace:</p>
  
  <pre><code>Caused by: org.eclipse.jetty.util.Utf8Appendable$NotUtf8Exception: Not valid UTF8! incomplete UTF8 sequence
      at org.eclipse.jetty.util.Utf8Appendable.checkState(Utf8Appendable.java:232) ~[jetty-util-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.util.Utf8StringBuffer.getStringBuffer(Utf8StringBuffer.java:65) ~[jetty-util-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.util.UrlEncoded.decodeString(UrlEncoded.java:843) ~[jetty-util-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.util.UrlEncoded.decodeTo(UrlEncoded.java:221) ~[jetty-util-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.Request.mergeQueryString(Request.java:2172) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:229) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:101) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.apache.jasper.runtime.PageContextImpl.forward(PageContextImpl.java:792) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
      at org.apache.jsp.WEB_002dINF.jsp.template.test_005jsp_jsp._jspService(test_005jsp_jsp.java:84) ~[na:na]
      at org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:111) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
      at org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:411) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
      at org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:473) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
      at org.apache.jasper.servlet.JspServlet.service(JspServlet.java:377) ~[javax.servlet.jsp-2.3.2.jar:2.3.2]
      at javax.servlet.http.HttpServlet.service(HttpServlet.java:790) ~[javax.servlet-api-3.1.0.jar:3.1.0]
      at org.eclipse.jetty.servlet.ServletHolder.handle(ServletHolder.java:696) ~[jetty-servlet-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.servlet.ServletHandler.doHandle(ServletHandler.java:526) [jetty-servlet-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:143) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.security.SecurityHandler.handle(SecurityHandler.java:586) ~[jetty-security-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.session.SessionHandler.doHandle(SessionHandler.java:221) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.handler.ContextHandler.doHandle(ContextHandler.java:1110) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.servlet.ServletHandler.doScope(ServletHandler.java:453) [jetty-servlet-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.session.SessionHandler.doScope(SessionHandler.java:183) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.handler.ContextHandler.doScope(ContextHandler.java:1044) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.handler.ScopedHandler.handle(ScopedHandler.java:141) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:261) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at org.eclipse.jetty.server.Dispatcher.forward(Dispatcher.java:101) ~[jetty-server-9.1.0.v20131115.jar:9.1.0.v20131115]
      at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method) ~[na:1.7.0_25]
      at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:57) ~[na:1.7.0_25]
      at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:43) ~[na:1.7.0_25]
      at java.lang.reflect.Method.invoke(Method.java:606) ~[na:1.7.0_25]
      at net.bull.javamelody.JspWrapper.invoke(JspWrapper.java:149) ~[javamelody-core-1.43.0.jar:1.43.0]
      at net.bull.javamelody.JdbcWrapper$DelegatingInvocationHandler.invoke(JdbcWrapper.java:271) ~[javamelody-core-1.43.0.jar:1.43.0]
      at com.sun.proxy.$Proxy51.forward(Unknown Source) ~[na:na]
      at org.apache.tiles.servlet.context.ServletTilesRequestContext.forward(ServletTilesRequestContext.java:241) ~[tiles-servlet-2.2.2.jar:2.2.2]
      ... 94 common frames omitted
  </code></pre>
  
  <p>I've found in the source code in the method mergeQueryString(String query) of class org.eclipse.jetty.server.Request following:</p>
  
  <pre><code>UrlEncoded.decodeTo(query,parameters, StandardCharsets.UTF_8,-1); //have to assume UTF-8 because we can't know otherwise
  </code></pre>
  
  <p>So in method URLEncoded.decodeTo() UTF-8 is used an not the encoding set with System.setProperty("org.eclipse.jetty.util.UrlEncoding.charset", "ISO-8859-1")</p>
  
  <p>Can I solve this somehow? Any ideas? :-)</p>