首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 软件管理 > 软件开发 >

servlet配备的整个过程

2013-01-07 
servlet配置的整个过程步骤:1.页面if(upForm.getForm().isValid()){upForm.form.submit({ waitMsg : 正在

servlet配置的整个过程

步骤:
1.页面

if(upForm.getForm().isValid()){      upForm.form.submit({ waitMsg : '正在上传文件,请稍候......',//提示信息 waitTitle : '请稍候',//标题 url : jutil.getRootPath()+'/nurseInfoImport.do', method : 'post', success : function(form, action) {  Ext.MessageBox.alert('提交成功', action.result.msg);     },  failure:function(form,action){//加载失败的处理函数  Ext.Msg.alert('提示','导入失败!'); }});}

2.web.xml
 <servlet>    <servlet-name>nurseInfoImport</servlet-name>    <servlet-class>com.alensic.nursing.sysmgr.NurseInfoImportServlet</servlet-class>  </servlet>  <servlet-mapping>    <servlet-name>nurseInfoImport</servlet-name>    <url-pattern>/nurseInfoImport.do</url-pattern>  </servlet-mapping>

3.servlet
package com.alensic.nursing.sysmgr;import java.io.FileInputStream;import java.io.IOException;import java.util.Iterator;import java.util.List;import javax.servlet.ServletException;import javax.servlet.http.HttpServlet;import javax.servlet.http.HttpServletRequest;import javax.servlet.http.HttpServletResponse;import org.apache.commons.fileupload.FileItem;import org.apache.tomcat.util.http.fileupload.DiskFileUpload;public class NurseInfoImportServlet extends HttpServlet {protected void doGet(HttpServletRequest request, HttpServletResponse response)      throws ServletException, IOException {doPost(request, response);}protected void doPost(HttpServletRequest request, HttpServletResponse response)              throws IOException, ServletException {          try {              System.out.println("开始进行文件上传");              DiskFileUpload fu = new DiskFileUpload();              fu.setSizeMax(100*1024*1024); // 设置最大文件尺寸,这里是4MB              fu.setSizeThreshold(4096); // 设置缓冲区大小,这里是4kb              List fileItems = fu.parseRequest(request); // 得到所有的文件:              Iterator i = fileItems.iterator();              // 依次处理每一个文件:              while (i.hasNext()) {                  FileItem fi = (FileItem) i.next();                  String fileName = fi.getName();// 获得文件名,这个文件名包括路径:                  ImportExcel importNurse = new ImportExcel();                importNurse.importExcel(new FileInputStream(fileName));            }              } catch (Exception e) {              e.printStackTrace();              response.getWriter().print("{success:flase,message:'失败'}");              // 可以跳转出错页面          }        }  }


配置是否成功可以通过直接访问路径:jutil.getRootPath()+/nurseInfoImport.do

热点排行