List of file with Delete option in JSP

ya , here is improved version of previous post. you can view all files within a particular directory as well as delete any file.

specially this kind of requirements came when i was working in Advertisement Management Module. so there admin can view all advertisement images which he uploaded previously and he can also able to delete from directory. so he can able to manage disk size.

k lets go for coding.

oky so first i need to fetch all images from directory with delete button. i m putting filename in button id value so i can easily recognize that for which file user pressing delete button. and once i’will get filename then rest of coding flow is very simple.. i will pass that filename to delete.jsp file and there i will write logic to delete that file.


JavaScript Function


and bellow screenshot is for listing of files from directory.


and now bellow jsp file show you delete function for that file

<%@ page import="*" %>
String id = request.getParameter("id"); 
File file = new File("C:\\Users\\LYMAN\\Documents\\NetBeansProjects\\WebApplication2\\web\\upload\\"+id+""); 
out.println("file deleted successfully");
else { 
	out.println("failed to perform delete operation"); 

hope you like this post.. 🙂


Leave a Reply

Fill in your details below or click an icon to log in: Logo

You are commenting using your account. Log Out /  Change )

Google+ photo

You are commenting using your Google+ account. Log Out /  Change )

Twitter picture

You are commenting using your Twitter account. Log Out /  Change )

Facebook photo

You are commenting using your Facebook account. Log Out /  Change )


Connecting to %s