Java Reference
In-Depth Information
method. The only thing to note about the HTML is that you ultimately have to call getBytes
on the string you produce because that's what the OutputStream accepts.
Here is the request that gets sent once you click the button on the form:
http://localhost:8080/restMaven/resources/forms/user
POST /restMaven/resources/forms/user HTTP/1.1
Host: localhost:8080
User-Agent: Mozilla/5.0 (X11; U; Linux i686; en-US; rv:1.8.0.7)
Gecko/20061011 Fedora/1.5.0.7-7.fc6 Firefox/1.5.0.7
Accept: text/xml,application/xml,application/xhtml+xml,text/html;
q=0.9,text/plain;q=0.8,image/png,*/*;q=0.5
Accept-Language: en-us,en;q=0.5
Accept-Encoding: gzip,deflate
Accept-Charset: ISO-8859-1,utf-8;q=0.7,*;q=0.7
Keep-Alive: 300
Connection: keep-alive
Referer: http://localhost:8080/restMaven/resources/forms/user
Content-Type: application/x-www-form-urlencoded
Content-Length: 31
id=88&fname=monty&submit=Create
The important thing to note about the request is that you have specified with the @Consumes
tag that a particular method will consume data for requests declaring that they send an ap-
plication/x-www-form-urlencoded Content-Type .
And here is the accompanying response:
HTTP/1.x 201 Created
Server: Apache-Coyote/1.1
Location: http://localhost:8080/restMaven/resources/forms/user/88
Content-Type: text/html
Content-Length: 314
Date: Fri, 07 Nov 2008 23:59:08 GMT
The important thing about the response is that it returns not a 200 OK HTTP status, but a 201
Created status. That's because you created an entity once the user posted the form data. But
you also return a Location header specifying the unique URI of the entity that you created.
This header is added by calling the location(createdUri) method on the ResponseBuild-
er object.
Search WWH ::




Custom Search