struts上传文件

StrutsActionForm项目中:

 

* 页面的配置,如:

<form action="upload.do" method="post" ectype="multipart/form-data" >

    标题:<input type="text" name="title"><br>

    文件:<input type="file" name="myfile"><br>

    <input type="submit" value="提交">

</form>

 

* ActionForm中使用FormFile来接受上传的文件,在Action中调用FormFile取得上传文件数据,并采用流输出:

UploadActionForm uaf = (UploadActionForm)form;

String title = uaf.getTitle();

FormFile myFile = uaf.getMyfile();

System.out.println("title = " + title);

if(myFile != null) {

    System.out.println("myfile = " + myFile.getFileName());

    FileOutputStream fos = new FileOutputStream("e://" + myFile.getFileName());

    fos.write(myFile.getFileData());

    fos.flush();

    fos.close();

}

return mapping.findForward("success");

 

* 采用<controller/>标签配置上传参数,如:<controller maxFileSize="10M"/>

你可能感兴趣的:(struts,File,null,input,action)