當前位置:編程學習大全網 - 網站源碼 - 求javaWeb大神!關於struts上傳文件的問題!

求javaWeb大神!關於struts上傳文件的問題!

頁面:

<form action="/struts3/demo/file" method="post" enctype="multipart/form">

<input type="file" name="some" />

<input type="submit" value="submit" />

</form>

action:

public class FileAction {

private File some;//頁面name屬性名,用於接受上傳文件

private String someFileName;//固定格式頁面name屬性名+FileName,用於保存文件名

//說明:struts負責幫妳接受文件,但是不保存,需要程序員自己保存到指定地點

public String execute(){

if(some==null){

return "error";

}

String path = "WEN-INF/upload"+someFileName;

path = ServletActionContext.getServletContext().getRealPath(path);

CopyFile.copy(some, new File("path"));

//自己定義的文件復制方法,將struts攔截的文件copy到指定地點保存

return "success";

}

public File getSome() {

return some;

}

public void setSome(File some) {

this.some = some;

}

public String getSomeFileName() {

return someFileName;

}

public void setSomeFileName(String someFileName) {

this.someFileName = someFileName;

}

}

  • 上一篇:Unity中C#如何實現物體在場景中隨機移動
  • 下一篇:請幫我把壹個子指數換成選股公式如下?
  • copyright 2024編程學習大全網