Win a copy of Head First Android this week in the Android forum!
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Paul Clapham
  • Ron McLeod
  • Tim Cooke
  • Junilu Lacar
Sheriffs:
  • Rob Spoor
  • Devaka Cooray
  • Jeanne Boyarsky
Saloon Keepers:
  • Jesse Silverman
  • Stephan van Hulst
  • Tim Moores
  • Carey Brown
  • Tim Holloway
Bartenders:
  • Jj Roberts
  • Al Hobbs
  • Piet Souris

doPut() & doDelete() in servltes

 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
HI All,
Can anybody show me how to use doPut() & doDelete() in servlets through demo program?
 
Ranch Hand
Posts: 569
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)
 
Ranch Hand
Posts: 294
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I don't understand " slide servlet"
Can u please explain me ?
 
Ranch Hand
Posts: 1704
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.

 
Sheriff
Posts: 13411
Firefox Browser VI Editor Redhat
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Marshal
Posts: 26910
82
Eclipse IDE Firefox Browser MySQL Database
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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.
 
Greenhorn
Posts: 11
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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)?
 
Ranch Hand
Posts: 8944
Firefox Browser Spring Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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".
 
Author and all-around good cowpoke
Posts: 13078
6
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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 ]
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic