jsp页面代码:
[code]
[/code]
xwork.xml配置:
[code]
index.jsp
[/code]
action处理:
[code]package com.iyouhe.test;
import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;
import java.util.Map;
import com.iyouhe.sessionFactory.TitleDao;
import com.iyouhe.sessionFactory.vo.Title;
import com.opensymphony.xwork.Action;
import com.opensymphony.xwork.ActionContext;
public class UploadAction implements Action {
private String title;
private String titleFile;
private File file;
String fileContentType;
public String execute() throws Exception {
// TODO Auto-generated method stub
ActionContext context=ActionContext.getContext();
Map map=context.getParameters();
context.getValueStack();
if(titleFile!=null)
{
FileOutputStream outputStream = new FileOutputStream("E:/myspace/aectwork/WebRoot/html/"
+ titleFile);
FileInputStream fileIn = new FileInputStream(file);
byte[] buffer = new byte[1024];
int len;
while ((len = fileIn.read(buffer)) > 0) {
outputStream.write(buffer, 0, len);
}
fileIn.close();
outputStream.close();
}
Title title=new Title();
title.setTitle(getTitle());
title.setTitleFile(titleFile);
TitleDao tt=new TitleDao();
tt.addTitle(title);
return "success";
}
public String getTitle() {
return title;
}
public void setTitle(String title) {
this.title = title;
}
public String getTitleFile() {
return titleFile;
}
public void setTitleFile(String titleFile) {
this.titleFile = titleFile;
}
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public String getFileContentType() {
return fileContentType;
}
public void setFileContentType(String fileContentType) {
this.fileContentType = fileContentType;
}
}
[/code]