Java Reference
In-Depth Information
list = client . target ( "http://localhost:8080/services/customers/uriinfo" )
. queryParam ( "start" , "2" )
. queryParam ( "size" , "2" )
. request (). get ( String . class );
The javax.ws.rs.client.WebTarget.queryParam() method is used to fill out the query
parameters for the invocation. This is a nice convenience method to use, especially if your
values might have characters that need to be encoded.
Build and Run the Example Program
Perform the following steps:
1. Open a command prompt or shell terminal and change to the ex05_1 directory of the
workbook example code.
2. Make sure your PATH is set up to include both the JDK and Maven, as described in
Chapter 17 .
3. Perform the build and run the example by typing maven install .
Example ex05_2: Forms and Cookies
The ex05_2 exercise includes examples of injecting form data, cookies, and HTTP headers
using the @FormParam , @CookieParam , and @HeaderParam annotations. This example is a bit
different than former examples, as there is no client code. Instead, to see these annotations in
action, you will use a browser as your client.
The Server Code
The example starts off with an HTML form defined in src/main/webapp/index.html :
<html>
<html>
<body>
<body>
<form
<form action= "/rest/customers" method= "post" >
First Name: <input
<input type= "text" name= "firstname" /><br/>
/><br/>
Last Name: <input
<input type= "text" name= "lastname" /><br/>
/><br/>
<INPUT type= "submit" value= "Send" >
</form>
<INPUT
</form>
</body>
</body>
</html>
</html>
It is a simple form for creating a customer using our familiar CustomerResource service:
Search WWH ::




Custom Search