简单的说就是怎么在struts中如何用jspsmartupload上传文件 ?请给个完整代码~~大虾们指点一下~~

解决方案 »

  1.   

    我用的是FileUpload:
    在jsp中使用 <html:file property="myFile"/>
    别忘了<html:form action="fileUpload.do" method="POST" enctype="multipart/form-data">
    在fileUpload.do的Action中
    FormFile myFile = (FormFile) form.get("myFile");(我用的动态form)
    byte[] data = zipFile.getFileData();得到你要的文件数据
    剩下的怎么处理应该不用说了吧
      

  2.   

    byte[] data = zipFile.getFileData();
    应该是
    byte[] data = myFile.getFileData();
    不好意思打错了
      

  3.   

    谢谢楼上几位
    我遇到的问题:
    type Exception report
    message 
    description The server encountered an internal error () that prevented it from fulfilling this request.
    exception 
    javax.servlet.ServletException: BeanUtils.populate
    org.apache.struts.util.RequestUtils.populate(RequestUtils.java:497)
    org.apache.struts.action.RequestProcessor.processPopulate(RequestProcessor.java:798)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:205)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1164)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:415)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:709)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:802)
    root cause 
    java.lang.IllegalArgumentException: argument type mismatch
    这是怎么回事?
    你们的jsp页面中怎么写的?
      

  4.   

    我的jsp页面
    <%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
    <%@taglib uri="/WEB-INF/struts-template.tld" prefix="template"%>
    <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@taglib uri="/WEB-INF/blnkcxt.tld" prefix="blnkcxt"%>
    <%@taglib uri="/WEB-INF/struts-nested.tld" prefix="nested"%>
    <%@page contentType="text/html; charset=GB18030" %>
    <html:html>
    <head>
    <meta http-equiv="Content-Type" content="text/html; charset=gb2312">
    <title>公民身份查询</title>
    <link rel="stylesheet" href="<%=request.getContextPath()%>/css/styles.css" type="text/css">
    </head><script language="javascript" type="text/javascript">
        function lakeSub(cmd){
          document.forms(0).cmd.value=cmd;
          document.forms(0).submit();
        }
    </script>
    <body background="<%=request.getContextPath()%>/images/bei.gif">
      <html:form action="/citizenIdentityInfoAction.do" method="post" enctype="multipart/form-data">
      <table width="50%" border="1" align="center" cellpadding="2" cellspacing="0" style="BORDER-COLLAPSE: collapse" bordercolor="#999999">
        <tr>
          <td height="50" colspan="2"><div align="center">公民身份批量查询</div></td>
        </tr>
        <tr>
          <td width="15%" ><div align="center">查询文件</div></td>
          <td width="85%" ><div align="center">
            <input type="file" name="file" value="">
            <input type="hidden" name="cmd" value="">
            <input name="button" type="button" onClick="lakeSub('searchN')" value="查询">
              <html:reset value="清空"/>
          </div></td>
        </tr>
        <tr><td colspan="2">
        <%
     String mes="";
     if(request.getAttribute("message")!=null)
     {
      mes=(String)  request.getAttribute("message");
      }
    %>
    <a href="<%=mes%>"><%=mes%></a>
    </td></tr>
      </table>
      </html:form>  </body>
    </html:html>一调试就出上面的问题 我jsp页面哪里出问题了?
      

  5.   

    你的jsp代码没什么问题,我在我的环境下执行正常,你看看你的actionForm里面是否有下面两个property:org.apache.struts.upload.FormFile file;
    java.lang.String cmd;只要有这两个property就没什么问题。