分类:
2008-10-16 19:25:10
view plaincopy to clipboardprint?
jsp中的表单view plaincopy to clipboardprint?
package com.actions;
import java.io.*;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class FileUploadActions extends ActionSupport {
private static final int BUFFER_SIZE=16*1024;
private File file;
private String contentType;
private String fileName;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public void setFileContentType(String contentType) {
this.contentType = contentType;
}
public void setFileFileName(String fileName) {
this.fileName = fileName;
}
public String execute(){
File dstFile=new File(ServletActionContext.getServletContext().getRealPath("/upload"+"/"+fileName));
try {
InputStream is=new BufferedInputStream(new FileInputStream(file),BUFFER_SIZE);
OutputStream os=new BufferedOutputStream(new FileOutputStream(dstFile),BUFFER_SIZE);
byte[] buffer=new byte[BUFFER_SIZE];
while(is.read(buffer)>0){
os.write(buffer);
}
is.close();
os.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
}
view plaincopy to clipboardprint?package com.actions; import java.io.*; import org.apache.struts2.ServletActionContext; import com.opensymphony.xwork2.ActionSupport; public class FileUploadActions extends ActionSupport { private static final int BUFFER_SIZE=16*1024; private File file; private String contentType; private String fileName; public File getFile() { return file; } public void setFile(File file) { this.file = file; } public void setFileContentType(String contentType) { this.contentType = contentType; } public void setFileFileName(String fileName) { this.fileName = fileName; } public String execute(){ File dstFile=new File(ServletActionContext.getServletContext().getRealPath("/upload"+"/"+fileName)); try { InputStream is=new BufferedInputStream(new FileInputStream(file),BUFFER_SIZE); OutputStream os=new BufferedOutputStream(new FileOutputStream(dstFile),BUFFER_SIZE); byte[] buffer=new byte[BUFFER_SIZE]; while(is.read(buffer)>0){ os.write(buffer); } is.close(); os.close(); } catch (Exception e) { // TODO Auto-generated catch block e.printStackTrace(); } return SUCCESS; } } package com.actions;
import java.io.*;
import org.apache.struts2.ServletActionContext;
import com.opensymphony.xwork2.ActionSupport;
public class FileUploadActions extends ActionSupport {
private static final int BUFFER_SIZE=16*1024;
private File file;
private String contentType;
private String fileName;
public File getFile() {
return file;
}
public void setFile(File file) {
this.file = file;
}
public void setFileContentType(String contentType) {
this.contentType = contentType;
}
public void setFileFileName(String fileName) {
this.fileName = fileName;
}
public String execute(){
File dstFile=new File(ServletActionContext.getServletContext().getRealPath("/upload"+"/"+fileName));
try {
InputStream is=new BufferedInputStream(new FileInputStream(file),BUFFER_SIZE);
OutputStream os=new BufferedOutputStream(new FileOutputStream(dstFile),BUFFER_SIZE);
byte[] buffer=new byte[BUFFER_SIZE];
while(is.read(buffer)>0){
os.write(buffer);
}
is.close();
os.close();
} catch (Exception e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
return SUCCESS;
}
}
view plaincopy to clipboardprint?
action代码
action代码view plaincopy to clipboardprint?
view plaincopy to clipboardprint?
image/bmp,image/png,image/gif,image/jpeg
index.jsp
index.jsp