国产探花免费观看_亚洲丰满少妇自慰呻吟_97日韩有码在线_资源在线日韩欧美_一区二区精品毛片,辰东完美世界有声小说,欢乐颂第一季,yy玄幻小说排行榜完本

首頁 > 學院 > 開發設計 > 正文

struts構建文件上傳(5)

2019-11-18 14:11:07
字體:
來源:轉載
供稿:網友

  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 + "http://sub" + "/" +
theFile.getFileName()); //建立一個上傳文件的輸出流
//System.out.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"));
}
}(未完待續)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 永年县| 花莲市| 林口县| 上林县| 漳州市| 资讯 | 吴江市| 炉霍县| 伊金霍洛旗| 平遥县| 巧家县| 胶南市| 龙胜| 岑巩县| 家居| 海伦市| 静安区| 三河市| 乌鲁木齐县| 尉氏县| 望城县| 太仓市| 霍州市| 隆子县| 巴里| 兴和县| 安多县| 图木舒克市| 沂南县| 南涧| 铁岭县| 乌兰浩特市| 朝阳市| 常州市| 出国| 博湖县| 河源市| 屏南县| 洛扎县| 准格尔旗| 龙川县|