How to retrieve params from GET HTTP method using javax.ws.rs.* and Glassfish?

Go To StackoverFlow.com

1

I just installed Glassfish V2 on my local machine just to play around with it.

I was wondering if there is a way to retrieve a param passed in by the GET HTTP method.

For instance,

http://localhost:8080/HelloWorld/resources/helloWorld?name=ABC

How do I retrieve the "name" param in my Java code?

2008-09-19 07:19
by Phu Son


2

Like this:

@Path("/helloWorld")
@Consumes({"application/xml", "application/json"})
@Produces({"application/xml", "application/json"})
@Singleton
public class MyService {
    @GET
    public String getRequest(@QueryParam("name") String name) {
            return "Name was " + name;
    }
}
2008-09-19 08:06
by tgdavies


0

By putting:

@Context
private UriInfo context;

in your HelloWorld class, can you access the

context.getQueryParameters() ;

method to get a map of parameters?

http://docs.sun.com/app/docs/doc/820-4867/ggrby?a=view

Seems to suggest you can :)

2008-09-19 08:11
by tim_yates
Ads