Tomcat, JAX-RS, Jersey, @PathParam: how to pass dots and slashes?

前端 未结 4 1463
我在风中等你
我在风中等你 2020-12-18 21:52

Having a method like this:

@GET @Path(\"/name/{name}\")
@Produces(MediaType.TEXT_PLAIN)
public String getProperty(@PathParam(\"name\") String name) {
                


        
4条回答
  •  独厮守ぢ
    2020-12-18 22:37

    Glassfish v4 accept encoded scape for slash %2f. Then we can pass the encoded String test.%2Ftest and get the result test./test using URLDecoder.decode(name, "UTF-8"). I think this is a better solution especially when you have many params in one request. Using the path @Path("/name/{name:.+}") is great solution when we have few parameters in a request.

    Using %252f complicates the client request becouse are needed to contruct the encoding request String manually. With glassfish v4 it's easy to use percent encoding with URLEncoder.encode in client and URLDecoder.decode in server to wished Strings. The most programing languages has percent encoding and decoding, therefore it's perfect solution.

    I tried enable encoded slash in glassfish v3 but no success, here is the sintaxe I tried used

    bin\asadmin set configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.encoded-slash-enabled=true configs.config.server-config.network-config.protocols.protocol.http-listener-1.http.encoded-slash-enabled=true

    Command set executed successfully.

    Regards Cassio Seffrin

提交回复
热议问题