Results 1 to 2 of 2
  1. #1
    puk284 is offline Member
    Join Date
    Apr 2009
    Rep Power

    Default Display file name


    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
    PrintWriter out = response.getWriter();
    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.

  2. #2
    FON is offline Senior Member
    Join Date
    Dec 2009
    Belgrade, Serbia
    Rep Power



    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:

    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!";
    			showError(request, response, message);
    		// 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! ";
    				showError(request, response, message);
    	// 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

  1. how to display content of .xls file in jsp
    By kirtichopra in forum Advanced Java
    Replies: 7
    Last Post: 09-15-2009, 04:07 PM
  2. Display the contents of a file on jsp page
    By shiva in forum JavaServer Pages (JSP) and JSTL
    Replies: 0
    Last Post: 03-30-2009, 01:01 PM
  3. display huge size file in jtextarea
    By tskarthic in forum AWT / Swing
    Replies: 1
    Last Post: 03-21-2009, 07:30 PM
  4. Display MS-Word file in browser
    By jazz2k8 in forum Advanced Java
    Replies: 6
    Last Post: 12-08-2008, 01:59 PM
  5. Cannot display a random string from .dat file
    By explosion242 in forum New To Java
    Replies: 2
    Last Post: 09-18-2008, 01:48 PM

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts