网站首页
JSP空间
动态资讯
开源项目
技术文档
资源下载
J2EE资源
客户论坛
在线支付
 
  技术文档>>JAVA>>新手入门>>基础入门>查看文档  
  struts构建文件上传(六)     
  文章作者:未知  文章来源:水木森林  
  查看:170次  录入:管理员--2007-11-17  
 
这是action页面,
package tester.business.maitain;

import tclcc.tester.util.selector;

import org.apache.struts.action.*;
import javax.servlet.http.*;
import java.util.*;
import org.apache.struts.upload.formfile;
import java.io.*;

public class maintainaction
extends action {
public actionforward execute(actionmapping actionmapping,
actionform actionform,
httpservletrequest httpservletrequest,
httpservletresponse httpservletresponse) {
/**@todo: complete the business logic here, this is just a skeleton.*/
maintainform maintainform = (maintainform) actionform;
trainplandao trainpdao = new trainplandao();
trainplan trainplan = new trainplan();
trainplan = maintainform.gettrainplan();
formfile thefile = null;
thefile = maintainform.getthefile1();
string p_accessory;
p_accessory = thefile.getfilename();
try {
inputstream stream = thefile.getinputstream(); //把文件读入
string filepath = httpservletrequest.getrealpath("/"); //取当前系统路径
bytearrayoutputstream baos = new bytearrayoutputstream();
outputstream bos = new fileoutputstream(filepath + "/sub" + "/" +
thefile.getfilename()); //建立一个上传文件的输出流
//system.out.println(filepath+"/"+file.getfilename());
int bytesread = 0;
byte[] buffer = new byte[8192];
while ( (bytesread = stream.read(buffer, 0, 8192)) != -1) {
bos.write(buffer, 0, bytesread); //将文件写入服务器
}
bos.close();
stream.close();
} catch (exception e) {
system.err.print(e);
}

try {
trainplan.setp_accessory(p_accessory);
trainpdao.addtrainplan(trainplan);//调用数据库插入方法
system.out.println("success");

} catch (exception ex) {
}
httpservletrequest.setattribute("trainplain", trainplan);
return (actionmapping.findforward("trainplancreated"));
}
}
 
 
上一篇: struts构建文件上传(四)    下一篇: struts构建文件上传(七)
  相关文档
effective java读书笔记之一 11-17
java:配置文件读取器 11-17
浅谈mda技术未来发展方向 11-17
关于editor和renderer的一点认识 11-17
多线程从线程继承 11-17
j2se综合--关于spring中的aop的解释 12-27
jive论坛与spring框架 11-17
一步一步用jbuilder5开发ejb(下) 11-17
《java与模式》读书笔记 ----模式设计的原则 11-17
java 数据对象(jdo)介绍(二) 11-17
利用httpsessionlistener统计在线人数 11-17
spring与weblogicserver的集成 11-17
scriptenginebuildversion 函数 11-16
mustang与rhino:java 6中的脚本编写 11-17
爪哇语言结构性模式之变压器模式介绍(下) 11-17
hello unicode —系统语言环境设置对java应用的影响 11-17
按位“或”运算符 (|) 11-16
对spring框架中接口注入理解的实例分析 11-16
j2me综合:如何在midp中实现图片放缩 11-17
开发框架hibernate3.0开发实例 11-17
返回首页 | 关于我们 | J网章程 | JSP空间合租 | 客服中心 | 免责声明 | 常见问题 | 参观机房
本站主机空间代理至厦门市华众网络科技有限公司
《中华人民共和国增值电信业务经营许可证》
编号:闽B2-20050079
@2005-2008福建JSP技术网 版权所有 闽ICP备05000928号
技术电话:13616026886
邮箱:admin@fjjsp.com 站长QQ,点击这里给我发消息