Struts2 上传文件问题。。大牛们帮帮忙吧。。。
上传文件的Action .
package com.login.action;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class Upload extends ActionSupport {
private String title;
private File upload;
private String uploadContentType;
private String filePath;
private String uploadFileName;
public String getUploadContentType() {
return uploadContentType;
}
public void setUploadContentType(String uploadContentType) {
this.uploadContentType = uploadContentType;
}
public String getFilePath() {
return ServletActionContext.getRequest().getRealPath(filePath);
}
public void setFilePath(String filePath) {
this.filePath = filePath;
}
public String getUploadFileName() {
return uploadFileName;
}
public void setUploadFileName(String uploadFileName) {
this.uploadFileName = uploadFileName;
}
public void setTitle(String title) {
this.title = title;
}
public String excute() throws Exception
{
//以服务器的文件保存地址和原文件名建立上传文件输出流
FileOutputStream fos=new FileOutputStream(getFilePath()+"\\"+getUploadFileName());
//以上传文件建立一个文件上传流
FileInputStream fis=new FileInputStream(getUpload());
//将上传文件的内容写入服务器
byte[] buffer=new byte[1024];
int len=0;
while((len=fis.read(buffer))>0)
{
fos.write(buffer,0,len);
}
System.out.println(getUploadContentType());
return SUCCESS;
}
public File getUpload() {
return upload;
}
public void setUpload(File upload) {
this.upload = upload;
}
public String getTitle() {
return title;
}
}
上传完文件如何用另一个Action将 文件名,文件路径等信息保存到数据库呢?
就是不知道如何将这个Actio的文件信息传到另外一个保存文件信息的Action里!!
[解决办法]
public String excute() throws Exception
里面就可以保持到数据库啊