love fish大鵬一曰同風(fēng)起,扶搖直上九萬(wàn)里

          常用鏈接

          統(tǒng)計(jì)

          積分與排名

          friends

          link

          最新評(píng)論

          在struts1.1框架下,利用smartupload實(shí)現(xiàn)文件的上傳(可以是多個(gè)文件)(轉(zhuǎn))

          1、前端頁(yè)面upload.jsp,后臺(tái)處理程序UplodAction.java
          2、struts.config的配置參數(shù)如下(沒(méi)有設(shè)置ActionForm):
          <action input="/upload.jsp"? path="/save" scope="request" type="yhp.test.web.UploadAction" validate="false">
          ????? <forward name="success" path="/list.do" />
          ??? </action>
          3、upload.jsp頁(yè)面中主要部分代碼
          <%@ page contentType="text/html; charset=GBK"%>
          <%@ taglib uri="http://jakarta.apache.org/struts/tags-html" prefix="html" %>
          <%@ taglib uri="http://java.sun.com/jstl/core" prefix="c" %>
          <html:html>
          <head>
          <title>?測(cè)試Struts利用SmartUpload上傳文件 </title>
          <meta http-equiv="Content-Type" content="text/html; charset=GBK">
          </head>
          <body>
          <html:form action="/save.do" styleId="formItem" method="post"? enctype="multipart/form-data">
          <html:hidden property="id"/>
          <html:file property="serverpath" styleClass="input-text"></html:file>
          </html:form>
          </body>
          </html:html>
          4、UploadAction.java
          import com.jspsmart.upload.File;
          import com.jspsmart.upload.Files;
          import com.jspsmart.upload.SmartUpload;

          public ActionForward doBatchsave(ActionMapping actionMapping,
          ???ActionForm actionForm, HttpServletRequest httpServletRequest,
          ???HttpServletResponse httpServletResponse) throws Exception {
          SmartUpload mySmartUpload = new SmartUpload();
          ??mySmartUpload.initialize(getServlet().getServletConfig(),httpServletRequest, httpServletResponse);??
          ??mySmartUpload.upload();
          ??//獲取除文件以外的相關(guān)信息,例如upload.jsp中隱藏控件id的值
          ??String strId=(String)mySmartUpload.getRequest().getParameter("id");
          ??Files files=mySmartUpload.getFiles();
          ??Collection col=files.getCollection();
          ??Iterator it=col.iterator();
          ??while(it.hasNext()){
          ??? File file=(File)it.next();????
          ????String oldFileName=file.getFileName();?????
          ????String extname=file.getFileExt();
          ????String fileName=Sequence.getSequence()+"."+extname;//產(chǎn)生一個(gè)唯一的文件名
          ????file.saveAs("c:\\temp\"+fileName);????
          ??}
          ??return (actionMapping.findForward("success"));

          posted on 2006-05-23 17:49 liaojiyong 閱讀(2603) 評(píng)論(1)  編輯  收藏 所屬分類(lèi): JSP

          評(píng)論

          # re: 在struts1.1框架下,利用smartupload實(shí)現(xiàn)文件的上傳(可以是多個(gè)文件)(轉(zhuǎn)) 2007-05-28 22:39 hanxianyong

          真的能行嗎?為什么我的程序,老是說(shuō)取不到文件  回復(fù)  更多評(píng)論   

          主站蜘蛛池模板: 白河县| 河东区| 邯郸市| 扶沟县| 池州市| 行唐县| 扎赉特旗| 平阳县| 山阳县| 潜山县| 什邡市| 千阳县| 绥化市| 确山县| 宁津县| 黔江区| 潜江市| 唐河县| 利津县| 东港市| 新乐市| 诏安县| 运城市| 左贡县| 怀远县| 米泉市| 湘潭县| 顺昌县| 镇原县| 兰州市| 德兴市| 镇雄县| 大新县| 博野县| 永新县| 年辖:市辖区| 黄梅县| 陇西县| 同仁县| 太仆寺旗| 淮滨县|