网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
Firefox | IE | Maxthon | 迅雷 | 电驴 | BitComet | FlashGet | QQ | QQ空间 | Vista | 输入法 | Ghost | Word | Excel | wps | Powerpoint
asp | .net | php | jsp | Sql | c# | Ajax | xml | Dreamweaver | FrontPages | Javascript | css | photoshop | fireworks | Flash | Cad | Discuz!
当前位置 > 网站建设学院 > 网络编程 > Java
Tag:注入,存储过程,分页,安全,优化,xmlhttp,fso,jmail,application,session,防盗链,stream,无组件,组件,md5,乱码,缓存,加密,验证码,算法,cookies,ubb,正则表达式,水印,索引,日志,压缩,base64,url重写,上传,控件,Web.config,JDBC,函数,内存,PDF,迁移,结构,破解,编译,配置,进程,分词,IIS,Apache,Tomcat,phpmyadmin,Gzip,触发器,socket
网络编程:ASP教程,ASP.NET教程,PHP教程,JSP教程,C#教程,数据库,XML教程,Ajax,Java,Perl,Shell,VB教程,Delphi,C/C++教程,软件工程,J2EE/J2ME,移动开发
本月文章推荐
.Hibernate中的Middlegen入门指南.
.Eclipse中自动重构实现探索.
.用JBuilder2005开发spring MVC应.
.在基于MIDP的应用程序上使用JDBC.
.权限系统:分散实现、关注变化.
.Keys 方法.
.来自Apache的Java开源项目.
.Java 理论与实践: 平衡测试,第 .
.关于applet写入文件的处理.
.为Web应用建立基于JMX的管理系统.
.如何用JDO开发数据库应用(1).
.异常处理优劣观.
.让界面更加绚丽 Java SE 6.0 GUI.
.JDBC 连接 各种数据库方法.
.扩展 Hibernate 对各类数据源支持.
.EJB核心技术及其应用(2).
.在PACKAGES之间建立关联.
.Java & XML基础学习笔记 SAX篇.
.在Web工程中实现任务计划调度.
.网络数据流的java处理(2).

struts构建文件上传(5)

发表日期:2008-1-5



  struts构建文件上传(5)

这是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标签 人气:811
下一篇:struts构建文件上传(3) 人气:1544
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐