views:

259

answers:

2

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?

+1  A: 

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;
 }
}
tdavies
A: 

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 :)

tim_yates