网络编程 | 站长之家 | 网页制作 | 图形图象 | 操作系统 | 冲浪宝典 | 软件教学 | 网络办公 | 邮件系统 | 网络安全 | 认证考试 | 系统进程
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,移动开发
本月文章推荐
.一个JAVA写的背单词程序.
.用Java制作十六进制编辑器.
.轻量组件与重量组件的比较.
.Java核心代码例程之:ThreadDemo.
.触摸Java编程中的“文档”和“包.
.设计表现层时需要考虑的几个问题.
.关于JAVA的字符编码问题.
.Java中“异常机制”深入研究.
.花二十分钟教你Ruby快速入门.
.Java核心代码例程之:JNIExample.
.Java 3D(JSR184)文件压缩.
.从XML元素结构到JAVA实现.
.提高J2EE层与数据库层交互操作能.
.applet调用javacomm20-win32API注.
.Java语言入门 -- 第二章 Java程.
.java数据库的实现.
.Java设计模式研究之Flyweight模式.
.Eclipse In Action 1.2.
.正则表达式常用功能—查询 提取 .
.java 类基础.

struts构建文件上传(六)

发表日期:2008-1-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的异常处理机制 人气:608
下一篇:struts构建文件上传(四) 人气:1724
浏览全部Java的内容 Dreamweaver插件下载 网页广告代码 祝你圣诞节快乐 2009年新年快乐