1 建立頁面
<form action="" name="form1" enctype="multipart/form-data" method="post">
2 建ActionForm類
private String title;
private FormFile file;//必須用apache的FormFile類(org.apache.struts.upload.FormFile)
3 建立Action類
UplodaActionForm uaf=(UplodaActionForm)form;
Systyem.out.println("title:"+uaf.getTitle());
FormFile file=uaf.getFile();
if(file!=null)
{
System.out.println("fileName:"+file.getFileName());
FileOutputStream fos=new FileOutputStream("c:\\"+file.getFileName());
fos.write(file.getFileData());
fos.flush();
fos.close();
}
return mapping.findForward("sessucc");
4 配置ActionForm和Action
<controller MaxFileSize="10M"></controller>該屬性可以配置上傳文件的大小等相關信息
posted on 2009-11-30 08:16
junly 閱讀(424)
評論(0) 編輯 收藏 所屬分類:
struts2/struts1.3/JSF