Jax-rs Receive parameter Note default is non-encoded

Source: Internet
Author: User

API Documentation Section
@Target ({elementtype.parameter, Elementtype.method, Elementtype.field}) @Retention (retentionpolicy.runtime) public @interface Formparam {    /**     * Defines the name of the form parameter whose value would be used     * to initialize T He value of the annotated method argument.     the name is * specified-decoded form, any percent encoded literals within the value * would not be     decoded and W Ill instead be treated as literal text.  e.g. if     * The parameter name is "a B" then the value of the annotation is "a B",     * <i>not</i> "a+b" or "a%20b".     *    /String value ();}

By default, it is not encoded.

The following is an introduction:

Https://access.redhat.com/documentation/en-US/JBoss_Enterprise_Web_Platform/5/html/RESTEasy_Reference_Guide/_ Encoded_and_encoding.html

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.EncodedAnnotation can used on a class, method, or parameter. By default, injected @PathParamand @QueryParamIs decoded. Adding the @EncodedAnnotation means that the value of these parameters would be is provided in encoded form.
@Path ("/") public class MyResource {  @Path ("/{param}")  @GET the public  String GET (@PathParam ("param") @ Encoded String param) {...}

  

In the previous example, the value of the @PathParamInjected into the paramof the get()Method would be URL encoded. Adding the @Encodedannotation as a parameter annotation triggers this effect. can also use the @Encodedannotation on the entire method and any combination of @QueryParamOr @PathParam' s values would be encoded.
@Path ("/") public class MyResource {     @Path ('/{param} ')   @GET   @Encoded public   String GET (@QueryParam ( "foo") string foo, @PathParam ("param") string param) {}}

  

In this example, the values of the fooQuery parameter and the paramPath parameter would be injected as encoded values. You can also set the default to being encoded for the entire class.
@Path ("/") @Encodedpublic class Classencoded {     @GET public   string GET (@QueryParam ("foo") string foo) {}}

  

The @Pathannotation have an attribute called encode. This controls whether the literal part of the "value supplied" (that's, the characters that's not part of a template vari Able) is url-encoded. If true , any characters in the URI template that is not valid would be automatically encoded. If false , then all characters must is valid URI characters. By default, the encode attribute are set to true . (You can also encode the characters by hand.)
@Path (value= "Hello%20world", Encode=false)

  

As with @Path.encode(), this controls whether the specified query parameter name should is encoded by the container before it tries to find the Query parameter in the request.
@QueryParam (value= "Hello%20world", Encode=false)

  

Jax-rs Receive parameter Note default is non-encoded

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.