Rest Web service parameter issue

using below code to test basic web service. When I go through the normal line, 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 doesn't give correct output for example - http://localhost.com:8080/CheckRest/rest/pmg?p1=xyz#abc . Then it 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;
      }
}

      

+3


source to share


1 answer


The pound / hash sign ( #

) indicates the start of the URL fragment identifier . If you want to use pound / hash sign in your query string, you need to encode the url by replacing it with %23

:



http://localhost.com:8080/CheckRest/rest/pmg?p1=xyz%23abc

+7


source







All Articles