国产探花免费观看_亚洲丰满少妇自慰呻吟_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"));
}
}(未完待續)

發表評論 共有條評論
用戶名: 密碼:
驗證碼: 匿名發表
主站蜘蛛池模板: 肃北| 托克逊县| 桦甸市| 当雄县| 镇康县| 克拉玛依市| 黔东| 外汇| 昌宁县| 梁河县| 丹巴县| 金堂县| 平昌县| 双牌县| 莱芜市| 启东市| 平顺县| 岐山县| 武乡县| 滨海县| 防城港市| 宝鸡市| 贞丰县| 江山市| 涪陵区| 鄂尔多斯市| 通渭县| 佛教| 民丰县| 泸水县| 民权县| 项城市| 介休市| 仁寿县| 辉南县| 广宁县| 长白| 伊金霍洛旗| 邓州市| 科尔| 鸡泽县|