我需要文件上传在结构2中,并将其存储到服务器位置,我使用Google没有用,任何人都可以提供更好的主意。先感谢文件上传在结构2
Q
文件上传在结构2
0
A
回答
1
谷歌,它可以帮助检查您键入的内容:这是“Struts2的”,没有“strurts”
无论如何,你不需要谷歌,官方文档是不够
http://struts.apache.org/2.2.1/docs/file-upload-interceptor.html
http://struts.apache.org/2.2.1/docs/handling-file-uploads.html
0
这里是Struts2的全码上传文件。
行动文件(fileupload.java)
package com.tutorialspoint.struts2;
import java.io.File;
import org.apache.commons.io.FileUtils;
import java.io.IOException;
import com.opensymphony.xwork2.ActionSupport;
public class uploadFile extends ActionSupport{
private File myFile;
private String myFileContentType;
private String myFileFileName;
private String destPath;
public String execute()
{
/* Copy file to a safe location */
destPath = "C:/apache-tomcat-6.0.33/work/";
try{
System.out.println("Src File name: " + myFile);
System.out.println("Dst File name: " + myFileFileName);
File destFile = new File(destPath, myFileFileName);
FileUtils.copyFile(myFile, destFile);
}catch(IOException e){
e.printStackTrace();
return ERROR;
}
return SUCCESS;
}
public File getMyFile() {
return myFile;
}
public void setMyFile(File myFile) {
this.myFile = myFile;
}
public String getMyFileContentType() {
return myFileContentType;
}
public void setMyFileContentType(String myFileContentType) {
this.myFileContentType = myFileContentType;
}
public String getMyFileFileName() {
return myFileFileName;
}
public void setMyFileFileName(String myFileFileName) {
this.myFileFileName = myFileFileName;
}
}
的index.jsp
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<%@ taglib prefix="s" uri="/struts-tags"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<title>File Upload</title>
</head>
<body>
<form action="upload" method="post" enctype="multipart/form-data">
<label for="myFile">Upload your file</label>
<input type="file" name="myFile" />
<input type="submit" value="Upload"/>
</form>
</body>
</html>
的success.jsp
<%@ page contentType="text/html; charset=UTF-8" %>
<%@ taglib prefix="s" uri="/struts-tags" %>
<html>
<head>
<title>File Upload Success</title>
</head>
<body>
You have successfully uploaded <s:property value="myFileFileName"/>
</body>
</html>
干杯。
相关问题
- 1. 上传文件的文件夹结构
- 2. HTTP文件上传响应结构
- 3. 无法在结构上上传DSYM文件?
- 4. 角2文件上传
- 5. 文件上传['错误'] = 2
- 6. 上传文件asp.net mvc 2
- 7. 上传2个文件php
- 8. EXTJS&PHP上传文件2
- 9. 角2上传文件
- 10. 多文件上传symfony 2
- 11. Angular 2 - 上传文件
- 12. HTTP文件上传2
- 13. Dropzone.js - 上传文件夹结构和单个文件
- 14. fineuploader上传带有文件夹结构的文件
- 15. 上传的图像/文件的文件夹结构?
- 16. NullPointException在Struts 2中上传文件
- 17. 在struts 2中上传多个文件
- 18. 上传图像/文件在asp.net MVC 2
- 19. 在Struts 2中上传多个文件
- 20. Ionic 2升级文件结构
- 21. 2结构内联合,从头文件
- 22. jQuery文件上传插件 - 空文件上传结果
- 23. jQuery的文件上传轨“错误空文件上传结果”
- 24. 上传的解剖结构
- 25. 翻新2:文件上传永不结束
- 26. Web文件上传器,支持选择整个目录结构
- 27. 任何网站上传php代码和文件组的结构?
- 28. Django的媒体上传设置和文件结构
- 29. 使用v2将文件夹结构上传到box.com API
- 30. 文件上传 - 目录结构的最佳实践?