Este conteúdo não está disponível no idioma selecionado.

Chapter 12. @Encoded and encoding


JAX-RS allows you to get encoded or decoded @*Params and specify path definitions and parameter names using encoded or decoded strings.
The @javax.ws.rs.Encoded annotation can be used on a class, method, or parameter. By default, injected @PathParam and @QueryParam are decoded. Adding the @Encoded annotation means that the value of these parameters will be provided in encoded form.
@Path("/")
public class MyResource {

  @Path("/{param}")
  @GET
  public String get(@PathParam("param") @Encoded String param) {...}
Copy to Clipboard Toggle word wrap
In the previous example, the value of the @PathParam injected into the param of the get() method will be URL encoded. Adding the @Encoded annotation as a parameter annotation triggers this effect.
You can also use the @Encoded annotation on the entire method and any combination of @QueryParam or @PathParam's values will be encoded.
@Path("/")
public class MyResource {
  
   @Path("/{param}")
   @GET
   @Encoded
   public String get(@QueryParam("foo") String foo, @PathParam("param") String param) {}
}
Copy to Clipboard Toggle word wrap
In this example, the values of the foo query parameter and the param path parameter will be injected as encoded values.
You can also set the default to be encoded for the entire class.
@Path("/")
@Encoded
public class ClassEncoded {
  
   @GET
   public String get(@QueryParam("foo") String foo) {}
}
Copy to Clipboard Toggle word wrap
The @Path annotation has an attribute called encode. This controls whether the literal part of the value supplied (that is, the characters that are not part of a template variable) are URL-encoded. If true, any characters in the URI template that are not valid will be automatically encoded. If false, then all characters must be valid URI characters. By default, the encode attribute is set to true. (You can also encode the characters by hand.)
@Path(value="hello%20world", encode=false)
Copy to Clipboard Toggle word wrap
As with @Path.encode(), this controls whether the specified query parameter name should be encoded by the container before it tries to find the query parameter in the request.
@QueryParam(value="hello%20world", encode=false)
Copy to Clipboard Toggle word wrap
Voltar ao topo
Red Hat logoGithubredditYoutubeTwitter

Aprender

Experimente, compre e venda

Comunidades

Sobre a documentação da Red Hat

Ajudamos os usuários da Red Hat a inovar e atingir seus objetivos com nossos produtos e serviços com conteúdo em que podem confiar. Explore nossas atualizações recentes.

Tornando o open source mais inclusivo

A Red Hat está comprometida em substituir a linguagem problemática em nosso código, documentação e propriedades da web. Para mais detalhes veja o Blog da Red Hat.

Sobre a Red Hat

Fornecemos soluções robustas que facilitam o trabalho das empresas em plataformas e ambientes, desde o data center principal até a borda da rede.

Theme

© 2025 Red Hat