I want to download a pdf file which is stored in the folder which is in WebContent of project

后端 未结 2 1195

This is my Strut file.


    

        
2条回答
  •  小蘑菇
    小蘑菇 (楼主)
    2021-01-22 22:16

    The problem with

    String path2=request.getParameter("path1");
    

    This method may return null if parameter path1 is missing. If it's not null then it should be a valid path to the readable file that you application has access.

    Read the example How to read file in Java – FileInputStream. You can trace the output with the code.

    System.out.println("Total file size to read (in bytes) : "
                    + getFileInputStream().available()); 
    

    The getter is needed to return a stream result, and as you are using dynamic parameter in the result config. You should provide the getter for fileName.

提交回复
热议问题