Extjs2.0的初体验

Extjs+struts实现文件上传
本人最近一直在研究extjs,感觉其功能强大复杂,前段时间做了个项目,要使用extjs实现文件上传,下面写出研究成果,与各位一起分享。
  1. Ext.Ajax.request({   
  2.     url:'/doc.do?method=deleteDocTag',   
  3.     success:function(){globalStore.load();},   
  4.     params:{tagId:u,docId:docId}   
  5.   });    


于是就想在Extjs中直接调用后台业务逻辑方法,但不知道这样如何实现,如何在url中写调用业务逻辑方法呢,盼哪位高手给小弟解惑,深表感谢!
Extjs+struts实现文件上传
本人最近一直在研究extjs,感觉其功能强大复杂,前段时间做了个项目,要使用extjs实现文件上传,下面写出研究成果,与各位一起分享。
1.fileUpload.js

Java代码 复制代码
  1. Ext.onReady(function(){    
  2.     
  3.   var form = new Ext.form.FormPanel({    
  4.      renderTo:'file',   
  5.      labelAlign: 'right',    
  6.      title: '文件上传',    
  7.      labelWidth: 60,    
  8.      frame:true,   
  9.      url: '../upload.do?op=uploadFile',//fileUploadServlet    
  10.      width: 300,    
  11.      height:200,   
  12.      fileUpload: true,   
  13.       
  14.   
  15.      items: [{    
  16.         xtype: 'textfield',    
  17.         fieldLabel: '文件名',    
  18.         name: 'file',    
  19.         inputType: 'file'//文件类型    
  20.       }],    
  21.         
  22.     buttons: [{    
  23.         text: '上传',    
  24.         handler: function() {    
  25.         form.getForm().submit({    
  26.         success: function(form, action){    
  27.            Ext.Msg.alert('信息''文件上传成功!');    
  28.         },    
  29.        failure: function(){    
  30.           Ext.Msg.alert('错误''文件上传失败');    
  31.        }    
  32.      });    
  33.     }    
  34.   }]    
  35.   });    
  36.   
  37.   }); 

2.uploadAction.java   其中使用了cos上传组件,下载地址:http://www.servlets.com/cos/cos-05Nov2002.zip

 

  1. package zx.struts.actions;   
  2.   
  3. import java.io.File;   
  4. import java.util.Enumeration;   
  5.   
  6. import javax.servlet.http.HttpServletRequest;   
  7. import javax.servlet.http.HttpServletResponse;   
  8.   
  9. import org.apache.struts.action.ActionForm;   
  10. import org.apache.struts.action.ActionForward;   
  11. import org.apache.struts.action.ActionMapping;   
  12.   
  13. import com.oreilly.servlet.MultipartRequest;   
  14.   
  15.   
  16. public class UploadAction extends DispatchAction{   
  17.     public ActionForward uploadFile(ActionMapping mapping, ActionForm form,   
  18.             HttpServletRequest request, HttpServletResponse response)throws Exception {   
  19.   
  20.            
  21.         String saveDirectory ="F://jboss-4.2.2.GA//server//default//deploy//userDemo.war//upload";      //文件上传后,保存的位置   
  22.   
  23.         int maxPostSize =3 * 5 * 1024 * 1024 ;   //每个文件最大5MB,最多3个文件,所以...    
  24.          
  25.         //response的编码为"gb2312"   
  26.         MultipartRequest multi =    
  27.                new MultipartRequest(request, saveDirectory, maxPostSize,    
  28.                                     "gb2312");    
  29.   
  30.         //输出反馈信息    
  31.          Enumeration files = multi.getFileNames();     
  32.              while (files.hasMoreElements()) {    
  33.                   
  34.                String name = (String)files.nextElement();    
  35.                File f = multi.getFile(name);    
  36.                if(f!=null){    
  37.                  String fileName = multi.getFilesystemName(name);    
  38.                  String lastFileName= saveDirectory+"//" + fileName;    
  39.                  System.out.println("上传的文件:"+lastFileName);    
  40.                     
  41.   
  42.                }    
  43.              }    
  44.   
  45.        
  46.    return null;   
  47. }   
  48. }  
Ext.onReady(function() {  

      var store1 = new Ext.data.SimpleStore({
        fields: [ 'id','role'],
        data :[['1','圈子1'],['2','圈子2']]
    });
   
    var form = new Ext.form.FormPanel({  
        renderTo : 'form',  
        title : '用户注册',  
        height : 200,  
        width : 400, 
        labelWidth : 100,  
        labelAlign : 'right',  
        frame : true,  
        waitMsgTarget:true,
        defaults : {  
            width : 180
        },  
      
       items: [  
            {  
               xtype : 'textfield', name : 'userName', fieldLabel : '用户名', allowBlank:false  
            },  
            {  
               xtype : 'textfield', name : 'password', fieldLabel : '密   码', inputType : 'password',allowBlank:false  
            },
            {  
               xtype : 'textfield', name : 'password1', fieldLabel : '确认密码', inputType : 'password',allowBlank:false  
            },  
          
            new Ext.form.ComboBox( {   
                         fieldLabel : '圈   子',   
                         name : 'role',   
                         mode: 'local',   
                         store : store1,   
                         displayField:'role',   
                         valueField: 'id',
                         triggerAction: 'all',
                         emptyText:'请选择圈子...',
                         allowBlank:false 
                         } )
             ],
       
         buttons: [{
            text: '提交',
            handler: function(){
            if(form.getForm().isValid()){
                   form.getForm().submit({
                    url:'../user.do?op=addEmploye',
                    waitMsg:'正在提交注册信息...'
                    //success: onRegSuccess,
                    //failure: onFailure
                });
            }else{
              Ext.Msg.alert('信息','请信息填写完成在提交!');
            }
            }
        },{
            text: '重置',
            handler: function(){
               form.getForm().reset();
            }},
            {
            text: '返回',
            handler: function(){
               window.location.href="javascript:history.back(-1)";
            }
        }]
    });  
}); 
上面是一个注册信息表单,当提交时我想判断密码和确认密码是否一致,请问各位大虾:如何获取输入的密码值呢,为什么我用form.getForm().password.value不对呢?谢谢各位了!

 

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值