如题,上网查了一天没找到解决办法,哪位老大帮帮忙啊

解决方案 »

  1.   

    <%@ page language="java" pageEncoding="utf-8"%><html>
     <head>
      <title>fileupload</title>
      <meta http-equiv="content-type" content="text/html; charset=utf-8">
      <%@ include file="/templates/header/ext.jsp"%>
      <script type="text/javascript">
    Ext.onReady(function() {
     Ext.lib.Ajax.defaultPostHeader += '; charset=utf-8'; 
     var form = new Ext.form.FormPanel({
      renderTo : 'file',
      labelAlign : 'right',
      title : 'fileupload',
      labelWidth : 70,
      frame : true,
      url : '../../add_swxx.do?action=save',// fileUploadServlet
      width : 380,
      height : 200,
      fileUpload : true,
      items : [{
       xtype : 'textfield',
       fieldLabel : 'file',
       name : 'file',
       inputType : 'file'
      }, {
       xtype : 'textfield',
       fieldLabel : 'file1',
       name : 'file1',
       inputType : 'file'
      }, {
       xtype : 'textfield',
       fieldLabel : 'file2',
       name : 'file2',
       inputType : 'file'
      },{
        xtype : "textfield",
        fieldLabel : 're',
        id : "re",
        allowBlank : true,
        anchor : "96%"
       }],  buttons : [{
       text : 'upload',
       handler : function() {
        Ext.MessageBox.show({
         title : 'Please wait',
         msg : 'Uploading...',
         progressText : '',
         width : 300,
         progress : true,
         closable : false,
         animEl : 'loding'    });
        form.getForm().submit({
         success : function(form, action) {
          Ext.Msg.alert('Tip', action.result.msg);
         },
         failure : function() {
          Ext.Msg.alert('Error', 'fail to upload');
         },
         waitMsg : 'uploading...'    });
       }
      }]
     });});
      </script>
     </head>
     <body>
      <DIV id=file>
     </body>
    </html></DIV>
      

  2.   

    java 代码
    String saveDirectory = "/home/caterpillar/files/";    
     // 限制上传之文件大小为 5 MB   
      int maxPostSize = 5 * 1024 * 1024 ;   
      MultipartRequest multi = new MultipartRequest(request ,saveDirectory , maxPostSize, "UTF-8");Enumeration filenames = multi.getFileNames(); 
    while(filenames.hasMoreElements()) { 
        String filename = (String) filenames.nextElement(); 
         out.println("上传了文件" + filename + "<br>"); 

      

  3.   

    问题解决:上传文件组件用jspSmartUpload.jar,这个网上可以下载
    我的前台代码,表单提交部分: function submit() {
    //     if (!upfile_form.getForm().isValid()) return;
    upfile_form.getForm().submit({
     waitMsg: '正在提交数据',
     waitTitle: '提示',
     url:'/upfileExt/servlet/upfileServlet',
    //  fileUpload:true, 
     method: 'post',
     success: function(re,v) {
      var jsonobject = Ext.util.JSON.decode(v.response.responseText);//将返回的JSON数据转换成JSON对象,转换失败即报错.
                     Ext.Msg.alert("msg,oject",jsonobject.msg);              
    //  Ext.Msg.alert('提示', '保存成功');
     },
     failure: function(re,v) {
     Ext.Msg.alert('提示', '上传失败');
     }
     });
     }

      

  4.   

    这是我的部分后台代码:
    public void doPost(HttpServletRequest request, HttpServletResponse response)
    throws ServletException, IOException {
    //获取各个变量的值

    FileUploadPO fup=new FileUploadPO();
        
        //上传文件
    SmartUpload upload=new SmartUpload();
    //初始化对象
    upload.initialize(this.getServletConfig(), request, response);

    //限制总上传数据的长度:字节,K,M
    upload.setTotalMaxFileSize(1024*1024*50);
    try {
    Date   now   =   new   Date();
    upload.initialize(this.getServletConfig(), request, response);
    upload.upload();
                            com.jspsmart.upload.Request rq = upload.getRequest();
                            String paperTitle = rq.getParameter("paperTitle");//paperTitle对应的前台界面是:{type:textfield,fieldLabel:'文章标题',name:'paperTitle',id:'paperTitle'}