Struts 2 file upload : File object being null

前端 未结 2 502
南旧
南旧 2020-12-20 06:32

I am trying to use Struts 2 file upload but it seems to me that its not working. Below is my code.

UploadAction.java:

public class Uploa         


        
2条回答
  •  鱼传尺愫
    2020-12-20 07:02

    Apart from changing the saveDir (really not necessary, and dangerous), your are not following the conventions in the Action class: the name of an private variable must match the names of its Getters and Setters; and finally, in page you are mismatching the name by pointing to the private variable, not the setter. Change it to:

    public class UploadAction extends ActionSupport{
    
        private File   upload;
        private String uploadFileName;
        private String uploadContentType;
    
        public void setUpload(File upload){
            this.upload=upload;
        }
        public void setUploadContentType(String uploadContentType){
            this.uploadContentType=uploadContentType;
        }
        public void setUploadFileName(String uploadFileName){
            this.uploadFileName=uploadFileName;
        }
    
        @Override
        public String execute(){
            if(upload==null)
            {
                System.out.println("No file....");
            }
            System.out.println(uploadContentType);
            System.out.println(uploadFileName);
            return SUCCESS;
        }
    }
    

    JSP

    
        
        
    
    

提交回复
热议问题