Home

doPut

doPut is a method in the Java Servlet API used to handle HTTP PUT requests. It is declared in the HttpServlet class and is invoked by the servlet container when a client sends a PUT request to a URL mapped to the servlet. If not overridden, the default HttpServlet doPut implementation responds with 405 Method Not Allowed.

Semantics: HTTP PUT targets a specific resource URI and is generally idempotent. The request body carries a

Implementation: override the method with the standard signature protected void doPut(HttpServletRequest req, HttpServletResponse resp) throws ServletException,

Relation to other methods: PUT targets a known URI and is distinct from POST, which is not

Example scenario: a RESTful file store may accept PUT /files/notes.txt with a payload containing file data; the

representation
of
the
resource
to
be
stored
at
that
URI.
A
successful
call
updates
an
existing
resource
or
creates
a
new
one
at
that
path.
Repeating
the
same
PUT
with
the
same
payload
must
produce
the
same
result.
IOException.
Within
it,
read
the
request
body
(for
example
via
req.getInputStream()),
determine
the
resource
location
from
the
request
path
(req.getPathInfo()),
perform
the
store
or
update,
and
set
an
appropriate
response
status
(for
example
200/204
for
success,
201
if
a
new
resource
was
created).
idempotent
and
may
create
sub-resources
or
trigger
actions.
In
RESTful
design,
PATCH
may
be
used
for
partial
updates,
while
PUT
often
implies
a
full
replacement
of
the
resource
content.
server
writes
the
content
to
the
file
and
returns
204
No
Content
on
success
or
201
Created
if
the
file
did
not
previously
exist.