Java Reference
In-Depth Information
String html = "<html><body><a href='step2'>Click</a> " +
"to go to the next step.</body></html>";
//include cookie in 200 OK response
Response response = Response.ok(html).cookie(cookie).build();
System.out.println("Built response.");
return response;
}
//retrieve cookie previously set
@GET
@Path("/step2")
public String step2(@CookieParam("MY_KEY") Cookie cookie) {
System.out.println("Step 2.");
String html = "";
if (cookie != null) {
System.out.println("Cookie Name: " + cookie.getName());
System.out.println("Cookie Value: " + cookie.getValue());
html = "<html><body>The value in your cookie was: " +
cookie.getValue() + "</body></html>";
} else {
html = "<html><body>Could not find cookie.
:(</body></html>";
}
System.out.println("Sending response for step2.");
return html;
}
}
Open your browser to http://localhost:8080/restMaven/resources/cookie/home , and you'll
send a request to the service that looks like this (it's just a snippet):
http://localhost:8080/restMaven/resources/cookie/home
GET /restMaven/resources/cookie/home HTTP/1.1
So you're accessing the GET method that corresponds to the /home mapping. That makes the
home method in the CookieService class respond to the request. Note that you have a class-
Search WWH ::




Custom Search