am using below code to test a basic web service. When am passing normal string it works fine for example - http://localhost.com:8080/CheckRest/rest/pmg?p1=xyz. It displays HELLO xyz
But when I add '#' to the URL it doesnt give the right output for example - http://localhost.com:8080/CheckRest/rest/pmg?p1=xyz#abc. It then displays HELLO xyz instead of HELLO xyz#abc
package com.check.ws;
import javax.ws.rs.GET;
import javax.ws.rs.Path;
import javax.ws.rs.Produces;
import javax.ws.rs.QueryParam;
import javax.ws.rs.core.MediaType;
@Path("/pmg")
public class CheckCall {
@GET
@Produces(MediaType.TEXT_PLAIN)
public String sayPlainTextHello() {
return " ";
}
// This method is called if XML is request
@GET
@Produces(MediaType.TEXT_XML)
public String sayXMLHello() {
return "<?xml version=\"1.0\"?>" + "<pmg> </pmg>";
}
// This method is called if HTML is request
@GET
@Produces(MediaType.TEXT_HTML)
public String sayHtmlHello(@QueryParam("p1") String par1) {
return "<html> <body> HELLO </body> </html>"+par1;
}
}
The pound/hash sign (#) indicates the beginning of the URL fragment identifier. If you want to use a pound/hash sign in your query string, you need to URL encode it by replacing it with %23:
http://localhost.com:8080/CheckRest/rest/pmg?p1=xyz%23abc
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With