JAVAWEB实验上传和下载_第1页
JAVAWEB实验上传和下载_第2页
JAVAWEB实验上传和下载_第3页
JAVAWEB实验上传和下载_第4页
JAVAWEB实验上传和下载_第5页
已阅读5页,还剩17页未读 继续免费阅读

下载本文档

版权说明:本文档由用户提供并上传,收益归属内容提供方,若内容存在侵权,请进行举报或认领

文档简介

/实验全过程记录实验名称上传和下载时间地点姓名学号实验目的:Html表单提交以与文件上传下载熟练运用Html表单提交以与文件上传下载二、实验内容:1、编写如下html表单,并编写servlet处理表单提交的请求,表单信息插入数据库2、如下表单,输入学号,点击“下载简历”按钮,实现下载该学生简历3、如下表单,输入最小最大值,点击提交按钮,导出符合条件的学生信息到文本文件(csv文件)中,或者导出到excel文件(使用POI框架)三、实验用设备仪器与材料:软件需求:Eclipse硬件需求:微型计算机四、实验方法与步骤:编写HTML页面(1)<formclass="form-horizontal"action="submit.do"method="post"id="stuId-form"enctype="multipart/form-data"> <divclass="form-group"id="messageId"> <divclass="col-sm-8"> <inputtype="text"name="Id"value="${student['id']}"> </div> </div> <divclass="form-group"> <labelfor="inputEmail3"class="col-sm-4control-label">学号</label> <divclass="col-sm-8"> <inputtype="text"class="form-control"id="inputstuId3"name="stuId"placeholder="学号"value="${student.stuId}"> </div> </div> <divclass="form-group"> <labelfor="inputPassword3"class="col-sm-4control-label">姓名</label> <divclass="col-sm-8"> <inputtype="text"class="form-control"id="inputname3"name="name"placeholder="姓名"value="${}"> </div> </div> <divclass="form-group"> <labelfor="inputage3"class="col-sm-4control-label">密码</label> <divclass="col-sm-8"> <inputtype="password"class="form-control"id="inputpassword3"name="password"placeholder="密码"value="${student.password}"> </div> </div> <divclass="form-group"> <labelclass="col-sm-4control-label">性别</label> <divclass="col-sm-8"> <inputtype="radio"name="sex"id="inlineRadio1"value="男" <c:iftest="${student.sex=='男'}">checked="checked"</c:if>/>男 <inputtype="radio"name="sex"id="inlineRadio2"value="女" <c:iftest="${student.sex=='女'}">checked="checked"</c:if>/>女 </div> </div> <divclass="form-group"> <labelfor="inputage3"class="col-sm-4control-label">年龄</label> <divclass="col-sm-8"> <inputtype="text"class="form-control"id="inputage3"name="age"placeholder="年龄"value="${student.age}"> </div> </div> <divclass="form-group"> <labelfor="inputage3"class="col-sm-4control-label">身高</label> <divclass="col-sm-8"> <inputtype="text"class="form-control"id="inputheight3"name="height"placeholder="身高"value="${student.height}"> </div> </div> <divclass="form-group"> <labelfor="inputage3"class="col-sm-4control-label">学院</label> <divclass="col-sm-8"> <selectclass="form-control"name="collage"id="collage"> <optionvalue="A"<c:iftest="${student.sex=='A'}">selectde</c:if>>软件学院</option> <optionvalue="B"<c:iftest="${student.sex=='B'}">selectde</c:if>>计院</option> <optionvalue="C"<c:iftest="${student.sex=='C'}">selectde</c:if>>经济学院</option> <optionvalue="D"<c:iftest="${student.sex=='D'}">selectde</c:if>>马克思主义学院</option> <optionvalue="E"<c:iftest="${student.sex=='E'}">selectde</c:if>>电气学院</option> </select> </div> </div> <divclass="form-group"> <labelfor="inputage3"class="col-sm-4control-label">照片</label> <divclass="col-sm-8"> <inputtype="file"id="inputPhoto3"name="photo"placeholder="浏览..."> </div> </div> <divclass="form-group"> <labelfor="inputage3"class="col-sm-4control-label">简历</label> <divclass="col-sm-8"> <inputtype="file"id="inputresume"name="resume"placeholder="浏览..."> </div> </div> <divclass="form-group"> <divclass="col-sm-offset-4col-sm-8"> <buttontype="button"class="btnbtn-default"id="formButton">提交</button> </div> </div> </form>(2)<formclass="form-horizontal"action="down.do"method="post"id="stuId-form"><divclass="form-group"><labelclass="col-sm-4control-label">简历下载</label></div><divclass="form-group"><labelfor="inputEmail3"class="col-sm-4control-label">学号</label><divclass="col-sm-8"><inputtype="text"class="form-control"id="inputstuId3"name="stuId"placeholder="学号"></div></div><divclass="form-group"><divclass="col-sm-offset-4col-sm-8"><buttontype="button"class="btnbtn-default"id="formButton">下载</button></div></div></form>(3)<formclass="form-horizontal"action="ExportServlet"method="post"id="stuId-form"> <divclass="form-group"> <labelclass="col-sm-4control-label">数据导出</label> </div> <divclass="form-group"> <labelfor="inputEmail3"class="col-sm-4control-label">年龄</label> <divclass="col-sm-3"> <inputtype="text"class="form-control"name="minAge"placeholder="年龄"> </div> <labelclass="col-sm-1control-label">--</label> <divclass="col-sm-3"> <inputtype="text"class="form-control"name="maxAge"placeholder="年龄"> </div> </div> <divclass="form-group"> <divclass="col-sm-offset-4col-sm-8"> <buttontype="button"class="btnbtn-default"id="formButton">导出</button> </div> </div> </form>编写相应的servlet(1)PartpartPhoto=request.getPart("photo");PartresumePart=request.getPart("resume");UploadServiceupload=newUploadService();StudentMessagemessage=newStudentMessage();StringphotoName=upload.get(partPhoto);StringresumeName=upload.get(resumePart);StringcontextPath=(String)request.getAttribute("contextPath");upload.writeTo(resumeName,resumePart,contextPath);upload.writeTo(photoName,partPhoto,contextPath);StringId=request.getParameter("Id")+"";StringstuId=request.getParameter("stuId");Stringname=request.getParameter("name");Stringage=request.getParameter("age");Stringsex=request.getParameter("sex");Stringpassword=request.getParameter("password");Stringheight=request.getParameter("height");Stringcollage=request.getParameter("collage");message.setAge((age!="")?Integer.parseInt(age):0);message.setCollage(collage);message.setHeight(height);message.setName(name);message.setPassword(password);message.setSex(sex);message.setStuId(stuId);message.setPhoto(photoName);message.setResume(resumeName);InsertIntoinsert=newInsertInto();UpdataServiceupDao=newUpdataService();if(Id.equals("")||Id==null){Id=System.currentTimeMillis()+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,response);}(2)StringstuId=request.getParameter("stuId");StudentMessagemessage=newStudentMessage();message.setStuId(stuId);Connectionconn=(Connection)request.getAttribute("dbconn");DownServicedown=newDownService();StringphotoName=down.selectResume(message,conn);StringphotoPath=request.getAttribute("contextPath")+;//response.setContentType(getMimeType(photoName));//设置Content-Dispositionresponse.setHeader("Content-Disposition","attachment;"+photoName);InputStreamin=new(photoPath);ServletOutputStreamout=response.getOutputStream();bytebuffer[]=newbyte[1024];intlen=0;while((len=in.read(buffer))>0){out.write(buffer,0,len);}in.close();out.close();(3)intminAge=Integer.parseInt(request.getParameter("minAge"));intmaxAge=Integer.parseInt(request.getParameter("maxAge"));Connectionconn=(Connection)request.getAttribute("dbconn");ExportExcelServiceexport=newExportExcelService();List<StudentMessage>list=export.selectByAge(minAge,maxAge,conn);HSSFWorkbookwb=newHSSFWorkbook();HSSFSheetsheet=wb.createSheet("学生表");sheet.setDefaultColumnWidth(15);HSSFCellStylestyle=wb.createCellStyle();HSSFRowrow=sheet.createRow(0);//style.setAlignment(HSSFCellStyle.ALIGN_CENTER);HSSFCellcell=row.createCell(0);cell.setCellValue("学号");cell.setCellStyle(style);cell=row.createCell(1);cell.setCellValue("姓名");cell.setCellStyle(style);cell=row.createCell(2);cell.setCellValue("年龄");cell.setCellStyle(style);cell=row.createCell(3);cell.setCellValue("性别");cell.setCellStyle(style);cell=row.createCell(4);cell.setCellValue("身高");cell.setCellStyle(style);cell=row.createCell(5);cell.setCellValue("学院");cell.setCellStyle(style);cell=row.createCell(6);cell.setCellValue("密码");cell.setCellStyle(style);cell=row.createCell(7);cell.setCellValue("照片");cell.setCellStyle(style);for(inti=0;i<list.size();i++){row=sheet.createRow(i+1);row.createCell(0).setCellValue(list.get(i).getStuId());

温馨提示

  • 1. 本站所有资源如无特殊说明,都需要本地电脑安装OFFICE2007和PDF阅读器。图纸软件为CAD,CAXA,PROE,UG,SolidWorks等.压缩文件请下载最新的WinRAR软件解压。
  • 2. 本站的文档不包含任何第三方提供的附件图纸等,如果需要附件,请联系上传者。文件的所有权益归上传用户所有。
  • 3. 本站RAR压缩包中若带图纸,网页内容里面会有图纸预览,若没有图纸预览就没有图纸。
  • 4. 未经权益所有人同意不得将文件中的内容挪作商业或盈利用途。
  • 5. 人人文库网仅提供信息存储空间,仅对用户上传内容的表现方式做保护处理,对用户上传分享的文档内容本身不做任何修改或编辑,并不能对任何下载内容负责。
  • 6. 下载文件中如有侵权或不适当内容,请与我们联系,我们立即纠正。
  • 7. 本站不保证下载资源的准确性、安全性和完整性, 同时也不承担用户因使用这些下载资源对自己和他人造成任何形式的伤害或损失。

评论

0/150

提交评论