How to create a Restful web service with input parameters?

前端 未结 5 741
花落未央
花落未央 2020-12-24 02:47

I am creating restful web service and i wanted to know how do we create a service with input parameters and also how to invoke it from a web browser.

For example

5条回答
  •  余生分开走
    2020-12-24 03:24

    You can try this... put parameters as :
    http://localhost:8080/WebApplication11/webresources/generic/getText?arg1=hello in your browser...

    package newpackage;
    
    import javax.ws.rs.core.Context;
    import javax.ws.rs.core.UriInfo;
    import javax.ws.rs.PathParam;
    import javax.ws.rs.Produces;
    import javax.ws.rs.Consumes;
    import javax.ws.rs.DefaultValue;
    
    
    import javax.ws.rs.GET;
    import javax.ws.rs.Path;
    import javax.ws.rs.PUT;
    import javax.ws.rs.QueryParam;
    
    @Path("generic")
    public class GenericResource {
    
        @Context
        private UriInfo context;
    
        /**
         * Creates a new instance of GenericResource
         */
        public GenericResource() {
        }
    
        /**
         * Retrieves representation of an instance of newpackage.GenericResource
    
         * @return an instance of java.lang.String
         */
        @GET
        @Produces("text/plain")
        @Consumes("text/plain")
        @Path("getText/")
        public String getText(@QueryParam("arg1")
                @DefaultValue("") String arg1) {
    
           return  arg1 ;  }
    
        @PUT
        @Consumes("text/plain")
        public void putText(String content) {
    
    
    
    
    
        }
    }
    

提交回复
热议问题