Mohana Madheswaran
Mohana Madheswaran

Reputation: 37

Get fragment (value hash '#') from a URL in jersey @PathParameter

How can I get the fragment (value hash '#') from a URL using Jersey @PathParameter?

@Path("Step2")

public class AdResource {

@GET
@Produces(MediaType.APPLICATION_JSON)
@Path("/{password:.+}/")
public String doResc(@PathParam("password") String pwd){
    System.out.println(pwd);
}

My URL is http://localhost:8080/Sample/webapi/Step2/Password@12#

but the password will be display "Password@12" only the hash(#) is missing..

Upvotes: 2

Views: 774

Answers (2)

eis
eis

Reputation: 53482

Since you seem to have a hash in your actual value, and it's not meant to be a fragment, it needs to be encoded before sending. URL encoding is the proper way to do it (like the other answer suggests).

Note also that there are other issues sending password in the url, such as it will be stored in different access logs, it will be part of browser url history etc. Usually you should not send it that way. Prefer POST body.

Upvotes: 1

Roger Dwan
Roger Dwan

Reputation: 770

Try to encode/decode the url. for javascript: encodeURI(uri)

then decode it in java using URLDecoder

Upvotes: 1

Related Questions