EXT制作了一个带有验证码的文件上传FORM

最近自己编写了一个EXR带有验证码的文件上传FORM,先看一个效果图,不多说了,看看代码吧

Index.jsp的代码

  1. <%@ page language="java" pageEncoding="GBK"%>
  2. <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
  3. <html>
  4.     <head>
  5.         <link rel="stylesheet" type="text/css"
  6.             href="ext-2.2/resources/css/ext-all.css">
  7.         <script type="text/javascript" src="ext-2.2/adapter/ext/ext-base.js"></script>
  8.         <script type="text/javascript" src="ext-2.2/ext-all.js"></script>
  9.         <script type="text/javascript"
  10.             src="ext-2.2/build/locale/ext-lang-zh_CN.js"></script>
  11.         <script type="text/javascript" src="jslib/form.js"></script>
  12.     </head>
  13.     <body>
  14.         <div id="formDiv"></div> <!-- form显示的地点-->
  15.     </body>
  16. </html>

 

FORM.JS的代码

  1. Ext.onReady(function(){
  2. Ext.QuickTips.init();
  3. Ext.form.Field.prototype.msgTarget = "qtip";
  4.   var f=new Ext.form.FormPanel({
  5.   renderTo:"formDiv",
  6.   timeout:60,
  7.   fileUpload: true,//file upload!
  8.   title:"DS",
  9.   height:250,
  10.   width:300,
  11.   labelWidth:60,
  12.   labelAlign:"left",
  13.   frame:true,
  14.   defaults:{xtype:"textfield",width:180},
  15.   items:[
  16.   {name:"username",fieldLabel:"Name",allowBlank:false,blankText:"Please Input Username"},
  17.   {name:"password",fieldLabel:"Password",allowBlank:false,inputType:"password", blankText:"Please Input Password"},
  18.   {name:"email",fieldLabel:"File" ,allowBlank:false,inputType:"file", allowBlank:false,blankText:"Please Input File Path"},
  19.   {
  20.      name: 'verifycode',
  21.      id: 'randCode',
  22.      fieldLabel: 'Verify Code',
  23.      maxLength: 4,
  24.      width: 80,
  25.      allowBlank: false,
  26.      blankText: 'Verify Code Can Not Be Empty!'
  27.   },
  28.   {xtype:"textarea",name:"intro",fieldLabel:"Result"}
  29.   ],
  30.   buttons:[{text:"OK",
  31.                 handler:function() {
  32.                  if(f.form.isValid()) {
  33.                         f.form.submit({
  34.                         waitTitle:"please wait for server executing..",
  35.                         waitMsg:"it is submiting..",
  36.                         url:"servlet/UploadServet",
  37.                         method:"POST",
  38.                         success:function(form,action)
  39.                         {
  40.                             reloadcode();    
  41.                             var su = action.result.success;
  42.                             Ext.Msg.alert("success",action.result.data['result0']);     
  43.                                                                  
  44.                         },
  45.                             failure:function(form,action) {
  46.                                reloadcode();    
  47.                                Ext.Msg.alert("failure",'Verify Code Wrong'); 
  48.                             }
  49.                         })
  50.                     }
  51.                 }
  52.   },
  53.   {text:"Cancel",
  54.     handler:function() {
  55.         f.form.reset();
  56.     }
  57.   }]  
  58.  })
  59.  var bd = Ext.getDom('randCode');
  60.     var bd2 = Ext.get(bd.parentNode);
  61.     bd2.createChild([{
  62.         tag: 'span',
  63.         html: '<a href="javascript:reloadcode();">'
  64.     }, {
  65.         tag: 'img',
  66.         id: 'safecode',
  67.         src: 'verify/verify.jsp',
  68.         align: 'absbottom'
  69.     }]);
  70. });
  71. function reloadcode(){
  72.     var verify = document.getElementById('safecode');
  73.     verify.setAttribute('src''verify/verify.jsp');
  74. }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值