Here is the sample code where you can see how we can implement doDelete() method in
servlet class.....
------------
public class DeleteDemoServlet extends HttpServlet{
public void init() throws ServletException{
//initialization code..
}
public void doGet(HttpServletRequest req, HttpServletResponse rs) throws IOException, ServletException{
}
public void doGet(HttpServletRequest req, HttpServletResponse rs) throws IOException, ServletException{
}
public void doDelete(HttpServletRequest req, HttpServletResponse
rs) throws IOException, ServletException{
boolean success = false;
// get the file to delete
File file=searchFile(request);
if (!file.exists()){
response.sendError(HttpServletResponse.SC_NOT_FOUND);
return;
}else{
//delete the file if it is exist.
success=file.delete(); // actual delete operation
}
if (success){
response.setStatus(HttpServletResponse.SC_NO_CONTENT);
}
}
public void destroy(){
// cleanup code....
}
}
Thanks,
Mahesh
---------
SCJP 1.4, SCWCD 1.4, SCBCD 1.3, (
SCEA Part I preparing......)