Java Reference
In-Depth Information
}
}
@FormParam
The @javax.ws.rs.FormParam annotation is used to access application/x-www-form-ur-
lencoded request bodies. In other words, it's used to access individual entries posted by an
HTML form document. For example, let's say we set up a form on our website to register
new customers:
<FORM
<FORM action= "http://example.com/customers" method= "post" >
<P>
<P>
First name: <INPUT
<INPUT type= "text" name= "firstname" ><BR>
><BR>
Last name: <INPUT
<INPUT type= "text" name= "lastname" ><BR>
><BR>
<INPUT
<INPUT type= "submit" value= "Send" >
</P>
</P>
</FORM>
</FORM>
We could post this form directly to a JAX-RS backend service described as follows:
@Path ( "/customers" )
public
public class
class CustomerResource
CustomerResource {
@POST
public
public void
void createCustomer ( @FormParam ( "firstname" ) String first ,
@FormParam ( "lastname" ) String last ) {
...
}
}
Here, we are injecting firstname and lastname from the HTML form into the Java para-
meters first and last . Form data is URL-encoded when it goes across the wire. When us-
ing @FormParam , JAX-RS will automatically decode the form entry's value before injecting
it.
@HeaderParam
The @javax.ws.rs.HeaderParam annotation is used to inject HTTP request header values.
For example, what if your application was interested in the web page that referred to or
linked to your web service? You could access the HTTP Referer header using the @Header-
Param annotation:
@Path ( "/myservice" )
public
public class
class MyService
MyService {
Search WWH ::




Custom Search