• Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

doPut() & doDelete() in servltes

 
Sonali Salunkhe
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
HI All,
Can anybody show me how to use doPut() & doDelete() in servlets through demo program?
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You don't normally need them. They are called when browser make an HTTP DELETE /PUT request - just do doPost() for POST. And I rarely see any browser would do this.
 
Sonali Salunkhe
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks for quick reply

I m new to J2EE& trying different things.

Normally we said doPut() method is used for uploading anything on server side.

Lets assume,i want to do the file upload in servlet,so if i go with post(), it works fine, but if i replace doPost() with doPut(), it won't work.

Does it mean that it depends on browser settings?( http version : 1.1)
 
dema rogatkin
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You may want to check slide servlet, I think it processes doPut and delete.
 
Sonali Salunkhe
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I don't understand " slide servlet"
Can u please explain me ?
 
Kj Reddy
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Sonali Salunkhe:
Thanks for quick reply

I m new to J2EE& trying different things.

Normally we said doPut() method is used for uploading anything on server side.

Lets assume,i want to do the file upload in servlet,so if i go with post(), it works fine, but if i replace doPost() with doPut(), it won't work.

Does it mean that it depends on browser settings?( http version : 1.1)


Sonali you are right. We use doPut() method for uploading a file on the server. From servlets api:

Called by the server (via the service method) to allow a servlet to handle a PUT request. The PUT operation allows a client to place a file on the server and is similar to sending a file by FTP.
 
Ben Souther
Sheriff
Posts: 13411
Firefox Browser Redhat VI Editor
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The standard way of uploading files these days is to use a third party library which processes multipart requests from the doPost method.

See:
http://faq.javaranch.com/view?FileUpload
for more details.
 
Alec Lee
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Just curious, would there be any situation that the browser would use any HTTP methods other than GET and POST? As far as I know, HTTP 1.1 also has HEAD, TRACE, OPTIONS, PUT, DELETE and CONNECT. But, I've never awared any of them being used.
 
Paul Clapham
Sheriff
Posts: 21416
33
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
It seems to me that if you had <form ... method="PUT"> in your HTML then the browser might possibly use the PUT method, and your doPut() method might possibly be called. Interested parties could try this.
 
Nicholas Way
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I was wondering about this, in particlar the TRACE and OPTIONS methods. Is there a default implementation - doTrace() and doOptions() - of these in HttpServlet, or would you have to write it yourself (and if so, what would you put in it)?
 
Pradeep bhatt
Ranch Hand
Posts: 8933
Firefox Browser Java Spring
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Originally posted by Paul Clapham:
It seems to me that if you had <form ... method="PUT"> in your HTML then the browser might possibly use the PUT method, and your doPut() method might possibly be called. Interested parties could try this.


The form only supports "GET" and "POST".
 
William Brogden
Author and all-around good cowpoke
Rancher
Posts: 13074
6
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I have been under the impression that a browser could use the HEAD method to determine if a resource has been modified since the time it was cached locally. Thus avoiding extra delays in (for example) showing a logo image.
So I was not surprised to find the doHead method in the abstract HttpServlet class as follows:

So it looks like your servlet will respond to a HEAD request by means of a special empty body. Obviously it would be better to create your own doHead if you want to avoid extra effort.
The default methods for DELETE and PUT send error responses, OPTIONS causes a complex lookup for the methods your servlet implements.
Bill
[ February 13, 2006: Message edited by: William Brogden ]
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic