Hi Leif,
Leif Gensert wrote:
> This questions seems rather stupid, but I don't know how to get the
> POST-parameters of a request. The GET-query-paramers are easy to get by
> the URIInfo object.
>
Not a stupid question. I blame Servlet for this type of confusion of
munging query parameters (that which are in the URI) with parameters of
a particular representation (of media type
"application/x-www-form-urlencoded") in a POST request.
> Can anybody help me? Can I get these Parameters as easy as I can get the
> parameters of the uri? (@Context URIInfo .....)
>
Currently you need to do this:
@POST
@ConsumeMime("application/x-www-form-urlencoded")
public void post(MultivaluedMap<String, String> form) { ... }
or
@POST
@ConsumeMime("application/x-www-form-urlencoded")
// Form is Jersey specific and implements
// MultivaluedMap<String, String>
// Note that Form was called FormURLEncodedProperties prior to 0.7
public void post(Form form) { ... }
There has been some good discussion on the list about having form beans
and having @FormParam:
https://jersey.dev.java.net/servlets/ReadMsg?list=users&msgNo=1083
The problem is not a technical one but a temporal one :-) looking for
any volunteers to help implement this.
BTW form parameters are really easy to test with curl:
curl -d "p1=a&p2=b"
http://localhost:9999/form
with the following resource:
@Path("form")
public class FormResource {
@POST
@ConsumeMime(MediaType.APPLICATION_FORM_URLENCODED)
public void post(Form form) {
System.out.println(form.getFirst("p1"));
System.out.println(form.getFirst("p2"));
}
}
Hope this helps,
Paul.
--
| ? + ? = To question
----------------\
Paul Sandoz
x38109
+33-4-76188109