Results 1 to 2 of 2
Thread: Display file name
- 03-07-2010, 09:13 PM #1
Member
- Join Date
- Apr 2009
- Posts
- 16
- Rep Power
- 0
Display file name
Hi,
I have a form linked to a servlet that uploads files. I would like the name of the file that has been uploaded to be displayed next to the <h3>line once it has been processed. I have no problems linking the servlet to the form or uploading the file. I simply want the name of the uploaded file to appear next to the word uploaded. Thank you for your help in advance.
// Generate some sample HTML
response.setContentType("text/html");
PrintWriter out = response.getWriter();
out.println("<html><head><title>Fileupload</title></head>");
out.println("<body>");
out.println("<h3>Your file has been successfully uploaded</h3>");
out.println("<h3>The following file was uploaded </h3>"); // Name of file should appear next to the word uploaded.
out.println("</body>");
out.println("</html>");
}
- 03-07-2010, 10:20 PM #2
Senior Member
- Join Date
- Dec 2009
- Location
- Belgrade, Serbia
- Posts
- 364
- Rep Power
- 4
Hi,
I'm using external library from
Apache Commons FileUpload API
to work with upload.
Here is part of code for upload servlet to help you:
...
cheers!Java Code:protected void [B]doPost[/B](HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String message = ""; // have file upload request been sent if (!ServletFileUpload.isMultipartContent(request)) { message = "File not sent!"; System.out.println(message); showError(request, response, message); return; } // if it is MultipartContent that is file // Parsing the form data with the Apache Jakarta Commons FileUpload library: try { ServletFileUpload servletFileUpload = new ServletFileUpload( new DiskFileItemFactory() ); List fileItemsList = servletFileUpload.parseRequest(request); // no need to iterate, there is only 1 member of list and it is file FileItem fileItem = (FileItem) fileItemsList.get(0); // true if the instance represents a simple form field; false if it represents an uploaded file if (fileItem.isFormField()) { message = " It's not file! "; System.out.println(message); showError(request, response, message); return; } // The file item contains an uploaded file System.out.println("The file item contains an uploaded file"); [B]System.out.println("file name : " + fileItem.getName()); [/B]System.out.println("file size: " + fileItem.getSize()); ...
Similar Threads
-
how to display content of .xls file in jsp
By kirtichopra in forum Advanced JavaReplies: 7Last Post: 09-15-2009, 04:07 PM -
Display the contents of a file on jsp page
By shiva in forum JavaServer Pages (JSP) and JSTLReplies: 0Last Post: 03-30-2009, 01:01 PM -
display huge size file in jtextarea
By tskarthic in forum AWT / SwingReplies: 1Last Post: 03-21-2009, 06:30 PM -
Display MS-Word file in browser
By jazz2k8 in forum Advanced JavaReplies: 6Last Post: 12-08-2008, 12:59 PM -
Cannot display a random string from .dat file
By explosion242 in forum New To JavaReplies: 2Last Post: 09-18-2008, 01:48 PM


LinkBack URL
About LinkBacks
Reply With Quote
Bookmarks