Java Reference
In-Depth Information
@GET
@Path("/{id}")
public Response viewOne(@PathParam("id") String id) {
User u = Database.users.get(id);
StringBuilder sb = new StringBuilder("<html><body>");
sb.append("<h1>View User Details</h1>");
sb.append("User ID: ").append(u.getId()).append("<br/>");
sb.append("Name: ").append(u.getName()).append("<br/>");
sb.append(String.format("Created On: %1$tm.%1$te.%1$tY",
u.getCreatedDate()) );
sb.append("</body></html>");
Response response = Response.ok(sb.toString()).build();
System.out.println("Built response.");
return response;
}
private static String NEW_USER_FORM_HTML =
new StringBuilder("<html><body>")
.append("<h1>Create User</h1>")
.append("<form name='userForm' method='POST' action=''>")
.append("ID: <input type='text' name='id' size='3' />")
.append("<br/>")
.append("Name: <input type='text' name='fname' />")
.append("<br/>")
.append("<input type='submit' name='submit' value='Create'/>")
.append("</form>")
.append("</body></html>").toString();
}
There is a lot going on in this class, but some of it we've seen before. Let's walk through what
it does, focusing on the most interesting aspects. A view of the application is shown in Fig-
ure 8-3 .
Search WWH ::




Custom Search