JAVAWEB實(shí)驗(yàn)上傳和下載_第1頁(yè)
JAVAWEB實(shí)驗(yàn)上傳和下載_第2頁(yè)
JAVAWEB實(shí)驗(yàn)上傳和下載_第3頁(yè)
JAVAWEB實(shí)驗(yàn)上傳和下載_第4頁(yè)
JAVAWEB實(shí)驗(yàn)上傳和下載_第5頁(yè)
已閱讀5頁(yè),還剩11頁(yè)未讀, 繼續(xù)免費(fèi)閱讀

下載本文檔

版權(quán)說(shuō)明:本文檔由用戶(hù)提供并上傳,收益歸屬內(nèi)容提供方,若內(nèi)容存在侵權(quán),請(qǐng)進(jìn)行舉報(bào)或認(rèn)領(lǐng)

文檔簡(jiǎn)介

1、實(shí)驗(yàn)全過(guò)程記錄實(shí) 驗(yàn)名 稱(chēng)上傳和下載時(shí)間地點(diǎn)姓 名 學(xué)號(hào)1、 實(shí)驗(yàn)?zāi)康模篐tml表單提交以及文件上傳下載熟練運(yùn)用Html表單提交以及文件上傳下載二、實(shí)驗(yàn)內(nèi)容:1、編寫(xiě)如下html表單,并編寫(xiě)servlet處理表單提交的請(qǐng)求,表單信息插入數(shù)據(jù)庫(kù)2、如下表單,輸入學(xué)號(hào),點(diǎn)擊“下載簡(jiǎn)歷”按鈕,實(shí)現(xiàn)下載該學(xué)生簡(jiǎn)歷3、如下表單,輸入最小最大值,點(diǎn)擊提交按鈕,導(dǎo)出符合條件的學(xué)生信息到文本文件(csv文件)中,或者導(dǎo)出到excel文件(使用POI框架)三、實(shí)驗(yàn)用設(shè)備儀器及材料:軟件需求:Eclipse硬件需求:微型計(jì)算機(jī)四、實(shí)驗(yàn)方法及步驟:1. 編寫(xiě)HTML頁(yè)面(1) 學(xué)號(hào)姓名密碼性別input type=

2、radio name=sex id=inlineRadio1 value=男 checked=checked / 男input type=radio name=sex id=inlineRadio2 value=女 checked=checked / 女年齡身高學(xué)院option value=A selectde軟件學(xué)院option value=B selectde計(jì)院option value=C selectde經(jīng)濟(jì)學(xué)院option value=D selectde馬克思主義學(xué)院option value=E selectde電氣學(xué)院照片簡(jiǎn)歷提交(2) 簡(jiǎn)歷下載 學(xué)號(hào) 下載 (3) 數(shù)據(jù)導(dǎo)出 年

3、齡-導(dǎo)出2. 編寫(xiě)相應(yīng)的servlet(1)Part partPhoto = request.getPart(photo); Part resumePart = request.getPart(resume); UploadService upload = new UploadService(); StudentMessage message = new StudentMessage(); String photoName = upload.getFileName(partPhoto); String resumeName = upload.getFileName(resumePart); S

4、tring contextPath = (String) request.getAttribute(contextPath); upload.writeTo(resumeName, resumePart, contextPath); upload.writeTo(photoName, partPhoto,contextPath); String Id = request.getParameter(Id)+; String stuId = request.getParameter(stuId); String name = request.getParameter(name); String a

5、ge = request.getParameter(age); String sex = request.getParameter(sex); String password = request.getParameter(password); String height = request.getParameter(height); String collage = request.getParameter(collage); message.setAge(age!=)?Integer.parseInt(age):0); message.setCollage(collage); message

6、.setHeight(height); message.setName(name); message.setPassword(password); message.setSex(sex); message.setStuId(stuId); message.setPhoto(photoName); message.setResume(resumeName); InsertInto insert = new InsertInto(); UpdataService upDao = new UpdataService(); if(Id.equals()|Id=null) Id = System.cur

7、rentTimeMillis()+stuId; System.out.println(Id); message.setId(Id); if(insert.insertData(message) System.out.println(插入成功); request.getRequestDispatcher(/login.jsp).forward(request, response); else message.setId(Id); upDao.updata(message); request.getRequestDispatcher(/show.do).forward(request, respo

8、nse); (2)String stuId = request.getParameter(stuId); StudentMessage message = new StudentMessage(); message.setStuId(stuId); Connection conn = (Connection) request.getAttribute(dbconn); DownService down = new DownService(); String photoName = down.selectResume(message, conn); String photoPath = requ

9、est.getAttribute(contextPath) + File.separator+photoName;/ response.setContentType(getMimeType(photoName); /設(shè)置Content-Disposition response.setHeader(Content-Disposition, attachment;filename=+photoName); InputStream in = new FileInputStream(photoPath); ServletOutputStream out = response.getOutputStre

10、am(); byte buffer = new byte1024; int len = 0; while(len=in.read(buffer)0) out.write(buffer,0,len); in.close(); out.close();(3)int minAge = Integer.parseInt(request.getParameter(minAge); int maxAge = Integer.parseInt(request.getParameter(maxAge); Connection conn = (Connection) request.getAttribute(d

11、bconn); ExportExcelService export = new ExportExcelService(); List list = export.selectByAge(minAge, maxAge, conn); HSSFWorkbook wb = new HSSFWorkbook(); HSSFSheet sheet = wb.createSheet(學(xué)生表); sheet.setDefaultColumnWidth(15); HSSFCellStyle style = wb.createCellStyle(); HSSFRow row = sheet.createRow(

12、0); /style.setAlignment(HSSFCellStyle.ALIGN_CENTER); HSSFCell cell = row.createCell(0); cell.setCellValue(學(xué)號(hào)); cell.setCellStyle(style); cell = row.createCell(1); cell.setCellValue(姓名); cell.setCellStyle(style); cell = row.createCell(2); cell.setCellValue(年齡); cell.setCellStyle(style); cell = row.cr

13、eateCell(3); cell.setCellValue(性別); cell.setCellStyle(style); cell = row.createCell(4); cell.setCellValue(身高); cell.setCellStyle(style); cell = row.createCell(5); cell.setCellValue(學(xué)院); cell.setCellStyle(style); cell = row.createCell(6); cell.setCellValue(密碼); cell.setCellStyle(style); cell = row.cr

14、eateCell(7); cell.setCellValue(照片); cell.setCellStyle(style); for (int i = 0; i list.size(); i+) row = sheet.createRow(i + 1); row.createCell(0).setCellValue(list.get(i).getStuId(); row.createCell(1).setCellValue(list.get(i).getName(); row.createCell(2).setCellValue(list.get(i).getAge(); row.createC

15、ell(3).setCellValue(list.get(i).getSex(); row.createCell(4).setCellValue(list.get(i).getHeight(); row.createCell(5).setCellValue(list.get(i).getCollage(); row.createCell(7).setCellValue(list.get(i).getPhoto(); row.createCell(6).setCellValue(list.get(i).getPassword(); try OutputStream out = response.getOutputStream(); response.reset(); response.setHeader(Content-disposition, attachment; filename=學(xué)生信息表.xls); response.setContentT

溫馨提示

  • 1. 本站所有資源如無(wú)特殊說(shuō)明,都需要本地電腦安裝OFFICE2007和PDF閱讀器。圖紙軟件為CAD,CAXA,PROE,UG,SolidWorks等.壓縮文件請(qǐng)下載最新的WinRAR軟件解壓。
  • 2. 本站的文檔不包含任何第三方提供的附件圖紙等,如果需要附件,請(qǐng)聯(lián)系上傳者。文件的所有權(quán)益歸上傳用戶(hù)所有。
  • 3. 本站RAR壓縮包中若帶圖紙,網(wǎng)頁(yè)內(nèi)容里面會(huì)有圖紙預(yù)覽,若沒(méi)有圖紙預(yù)覽就沒(méi)有圖紙。
  • 4. 未經(jīng)權(quán)益所有人同意不得將文件中的內(nèi)容挪作商業(yè)或盈利用途。
  • 5. 人人文庫(kù)網(wǎng)僅提供信息存儲(chǔ)空間,僅對(duì)用戶(hù)上傳內(nèi)容的表現(xiàn)方式做保護(hù)處理,對(duì)用戶(hù)上傳分享的文檔內(nèi)容本身不做任何修改或編輯,并不能對(duì)任何下載內(nèi)容負(fù)責(zé)。
  • 6. 下載文件中如有侵權(quán)或不適當(dāng)內(nèi)容,請(qǐng)與我們聯(lián)系,我們立即糾正。
  • 7. 本站不保證下載資源的準(zhǔn)確性、安全性和完整性, 同時(shí)也不承擔(dān)用戶(hù)因使用這些下載資源對(duì)自己和他人造成任何形式的傷害或損失。

評(píng)論

0/150

提交評(píng)論