title: Jersey - The servlet context path and/or the servlet path contain characters that are percent encoded
body: <p>I am using Jersey and Tomcat and I am getting the following message whenever I click a link:</p>
  
  <pre><code>HTTP Status 500 - The servlet context path and/or the servlet path contain
  characters that are percent encoded
  
  type: Exception report
  
  message: The servlet context path and/or the servlet path contain characters
           that are percent encoded
  
  description: The server encountered an internal error that prevented it from
               fulfilling this request.
  
  exception:
      javax.ws.rs.ProcessingException: The servlet context path and/or the servlet path
      contain characters that are percent encoded
          org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:317)
          org.glassfish.jersey.servlet.ServletContainer.service(ServletContainer.java:221)
          org.apache.tomcat.websocket.server.WsFilter.doFilter(WsFilter.java:52)
  
  note: The full stack trace of the root cause is available in the Apache Tomcat/7.0.56
        logs.
  </code></pre>
  
  <p>The path to the REST service is:</p>
  
  <pre><code>http://localhost:8070/simple-service-webapp/rest/hello
  </code></pre>
  
  <p>When I type this into the URL bar it works, but when I click on a link somewhere on the way the URL becomes this:</p>
  
  <pre><code>http://localhost:8070/simple%2Dservice%2Dwebapp/rest/hello
  </code></pre>
  
  <p>And somehow Jersey does not deal with percent encoded URLs by default.</p>
  
  <p>Can someone please help me get this to work without removing the dash in the URL? My search did not provide a working solution.</p>
  
  <h2>Listings</h2>
  
  <p><strong>HelloResource.java</strong></p>
  
  <pre><code>package com.example;
  
  import javax.ws.rs.*;
  import javax.ws.rs.core.Context;
  import javax.ws.rs.core.MediaType;
  import javax.ws.rs.core.UriInfo;
  
  @Path("hello")
  public class HelloResource {
  
      @GET
      @Produces(MediaType.TEXT_PLAIN)
      public String sayHelloPlainText(@Context UriInfo uriInfo) {
  
          String name = uriInfo.getQueryParameters().getFirst("name");
  
          if (name == null) {
              name = "unknown user";
          }
  
          return "Hello " + name + "!";
      }
  
      @GET
      @Produces(MediaType.TEXT_HTML)
      public String sayHelloHtml(@Context UriInfo uriInfo) {
  
          String text = sayHelloPlainText(uriInfo);
  
          String result = "&lt;html&gt;" + "&lt;head&gt;" + "&lt;title&gt;Hello Jersey&lt;/title&gt;" + "&lt;/head&gt;"
                        + "&lt;body&gt;" + "&lt;h1&gt;" + text + "&lt;/h1&gt;" + "&lt;/body&gt;" + "&lt;/html&gt;";
  
          return result;
      }
  
      @GET
      @Produces(MediaType.TEXT_XML)
      public String sayHelloXml(@Context UriInfo uriInfo) {
  
          String text = sayHelloPlainText(uriInfo);
  
          String result = "&lt;?xml version=\"1.0\"?&gt;" + "&lt;hello&gt;Hello " + text + "!" + "&lt;/hello&gt;";
  
          return result;
      }
  }
  </code></pre>
  
  <p><strong>index.jsp</strong></p>
  
  <pre><code>&lt;!DOCTYPE html&gt;
  
  &lt;html&gt;
  
  &lt;head&gt;
      &lt;meta charset="UTF-8"&gt;
  
      &lt;title&gt;RESTful Web Application&lt;/title&gt;
  &lt;/head&gt;
  
  &lt;body&gt;
      &lt;h2&gt;My RESTful Web Application!&lt;/h2&gt;
  
      &lt;ul&gt;
          &lt;li&gt;&lt;a href="rest/hello"&gt;Hello from Jersey&lt;/a&gt;&lt;/li&gt;
          &lt;li&gt;&lt;a href="rest/hello?name=Johannes"&gt;Hello using parameters&lt;/a&gt;&lt;/li&gt;
      &lt;/ul&gt;
  &lt;/body&gt;
  
  &lt;/html&gt;
  </code></pre>
  
  <p><strong>web.xml</strong></p>
  
  <pre><code>&lt;?xml version="1.0" encoding="UTF-8"?&gt;
  
  &lt;web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
           xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
           version="3.1"&gt;
  
      &lt;servlet&gt;
          &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
          &lt;servlet-class&gt;org.glassfish.jersey.servlet.ServletContainer&lt;/servlet-class&gt;
  
          &lt;init-param&gt;
              &lt;param-name&gt;jersey.config.server.provider.packages&lt;/param-name&gt;
              &lt;param-value&gt;com.example&lt;/param-value&gt;
          &lt;/init-param&gt;
  
          &lt;load-on-startup&gt;1&lt;/load-on-startup&gt;
      &lt;/servlet&gt;
  
      &lt;servlet-mapping&gt;
          &lt;servlet-name&gt;Jersey Web Application&lt;/servlet-name&gt;
          &lt;url-pattern&gt;/rest/*&lt;/url-pattern&gt;
      &lt;/servlet-mapping&gt;
  &lt;/web-app&gt;
  </code></pre>
  
  <p><strong>pom.xml</strong></p>
  
  <pre><code>&lt;project xmlns="http://maven.apache.org/POM/4.0.0" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
           xsi:schemaLocation="http://maven.apache.org/POM/4.0.0 http://maven.apache.org/maven-v4_0_0.xsd"&gt;
  
      &lt;modelVersion&gt;4.0.0&lt;/modelVersion&gt;
  
      &lt;groupId&gt;com.example&lt;/groupId&gt;
      &lt;artifactId&gt;simple-service-webapp&lt;/artifactId&gt;
      &lt;packaging&gt;war&lt;/packaging&gt;
      &lt;version&gt;1.0-SNAPSHOT&lt;/version&gt;
      &lt;name&gt;simple-service-webapp&lt;/name&gt;
  
      &lt;properties&gt;
          &lt;project.build.sourceEncoding&gt;UTF-8&lt;/project.build.sourceEncoding&gt;
  
          &lt;jersey.version&gt;2.16&lt;/jersey.version&gt;
      &lt;/properties&gt;
  
      &lt;dependencyManagement&gt;
          &lt;dependencies&gt;
              &lt;dependency&gt;
                  &lt;groupId&gt;org.glassfish.jersey&lt;/groupId&gt;
                  &lt;artifactId&gt;jersey-bom&lt;/artifactId&gt;
                  &lt;version&gt;${jersey.version}&lt;/version&gt;
                  &lt;type&gt;pom&lt;/type&gt;
                  &lt;scope&gt;import&lt;/scope&gt;
              &lt;/dependency&gt;
          &lt;/dependencies&gt;
      &lt;/dependencyManagement&gt;
  
      &lt;dependencies&gt;
          &lt;dependency&gt;
              &lt;groupId&gt;org.glassfish.jersey.containers&lt;/groupId&gt;
              &lt;artifactId&gt;jersey-container-servlet&lt;/artifactId&gt;
          &lt;/dependency&gt;
      &lt;/dependencies&gt;
  
      &lt;build&gt;
          &lt;finalName&gt;simple-service-webapp&lt;/finalName&gt;
  
          &lt;plugins&gt;
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.maven.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;maven-compiler-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.5.1&lt;/version&gt;
  
                  &lt;inherited&gt;true&lt;/inherited&gt;
  
                  &lt;configuration&gt;
                      &lt;source&gt;1.7&lt;/source&gt;
                      &lt;target&gt;1.7&lt;/target&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.wildfly.plugins&lt;/groupId&gt;
                  &lt;artifactId&gt;wildfly-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;1.0.2.Final&lt;/version&gt;
  
                  &lt;configuration&gt;
                      &lt;id&gt;WildFlyServer&lt;/id&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
  
              &lt;plugin&gt;
                  &lt;groupId&gt;org.apache.tomcat.maven&lt;/groupId&gt;
                  &lt;artifactId&gt;tomcat7-maven-plugin&lt;/artifactId&gt;
                  &lt;version&gt;2.2&lt;/version&gt;
  
                  &lt;configuration&gt;
                      &lt;server&gt;TomcatServer&lt;/server&gt;
  
                      &lt;url&gt;http://localhost:8070/manager/text&lt;/url&gt;
                  &lt;/configuration&gt;
              &lt;/plugin&gt;
          &lt;/plugins&gt;
      &lt;/build&gt;
  &lt;/project&gt;
  </code></pre>