package com.jzaccp.web;import java.io.File;
import java.io.FileInputStream;
import java.io.FileOutputStream;import org.apache.commons.io.CopyUtils;
import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class Save extends ActionSupport {
private File file; public File getFile() {
return file;
} public void setFile(File file) {
this.file = file;
} public String execute() throws Exception {
if (file!=null) {
String path=ServletActionContext.getServletContext().getRealPath("/image");
FileInputStream inputStream=new FileInputStream(file);
File save=new File(path,file.getName()); FileOutputStream outputStream=new FileOutputStream(save);
CopyUtils.copy(inputStream, outputStream);
inputStream.close();
outputStream.close();
//为什么我得到的文件总是.tmp的后缀 }
return SUCCESS;
}
}我的网页
<form action="upload.do" method="post" enctype="multipart/form-data" >
<label>
<input type="file" name="file" id="fileField">
<input type="text" name="fileName" id="fileField">
</label>
<label>
<input type="submit" name="button" id="button" value="提交">
</label>
</form>
import java.io.FileInputStream;
import java.io.FileOutputStream;import org.apache.commons.io.CopyUtils;
import org.apache.struts2.ServletActionContext;import com.opensymphony.xwork2.ActionSupport;public class Save extends ActionSupport {
private File file; public File getFile() {
return file;
} public void setFile(File file) {
this.file = file;
} public String execute() throws Exception {
if (file!=null) {
String path=ServletActionContext.getServletContext().getRealPath("/image");
FileInputStream inputStream=new FileInputStream(file);
File save=new File(path,file.getName()); FileOutputStream outputStream=new FileOutputStream(save);
CopyUtils.copy(inputStream, outputStream);
inputStream.close();
outputStream.close();
//为什么我得到的文件总是.tmp的后缀 }
return SUCCESS;
}
}我的网页
<form action="upload.do" method="post" enctype="multipart/form-data" >
<label>
<input type="file" name="file" id="fileField">
<input type="text" name="fileName" id="fileField">
</label>
<label>
<input type="submit" name="button" id="button" value="提交">
</label>
</form>
解决方案 »
- Applet交互问题
- 《===============求能解决实际开发问题的java技术群==============》
- resin 部署的工程 找不到 新加入jar包
- 用jfreechart实现折线图横坐标的问题!
- spring容器问题
- 选择一个本地文件,然后存入远程的数据库中
- 192.168.*的内网IP怎么进行远程调ejb的bean啊?
- 这个jsp文件是怎么回事?
- 能否给个Rmi的简单例子,包括策略文件,在线等待
- spring mvc 访问静态资源疑问
- List 中 存放 几百条数据 同搜索去处数据 怎么实现好些?
- Struts 集成Hibernate修改数据时 argument type mismatch异常,请高手们解决
private String fileContentType;