爱问 爱问共享资料 爱问分类
首页 > > > Extjs如何与数据库交互.doc

Extjs如何与数据库交互.doc

Extjs如何与数据库交互.doc

上传者: zhangpeng2084
640次下载 0人收藏 暂无简介 简介 2011-12-25 举报

简介:extjs

一般需要添加一组数据,引入一个概念Ext.data.Reader,这里的Reader功能非常单一,只是用来解析数据的到,EXTJS支持不同的数据格式,也就需要不同的数据解析器。而这个Reader就是承担解析器的作用。1、数组形式数据解析(特殊的JSON形式数据,因此,ArrayReader是JsonReader的子类)var_store=newExt.data.Store({        data:[["陈治文","男"],["张妍娜","女"]],        reader:newExt.data.ArrayReader({             },Ext.data.Record.create(["name","sex"]))        });解析器为ArrayReader,分别解析["陈治文","男"]和["张妍娜","女"],将其转换成Ext.data.Record。2、JSON形式数据var_store=newExt.data.Store({         data:[{name:"陈治文",sex:"男"},{name:"张妍娜",sex:"女"}],         reader:newExt.data.JsonReader({              },Ext.data.Record.create(["name","sex"]))        });           alert(_store.getCount());JsonReader分别解析{name:"陈治文",sex:"男"}和{name:"张妍娜",sex:"女"},将这些数据解析成Ext.data.Record类型数据3、XML形式数据这里的有个地方比较麻烦,首先,我们必须得构建一个XMLDocument,这样才能形成XML数据,我们这里所讲的是ASPServer的XML组织形式var_xml=newXML("<table><row><name>陈治文</name><sex>男</sex></row><row><name>张妍娜</name><sex>女</sex></row></table>");这样,就是构建一个XML对象,通过_xml.getValue()得到xmldocument原型再者,我们还有需要引入一个新型概念——数据代理Ext.data.DataProxy,数据代理的作用就是通过一定的方式来获得数据,目前EXTJS提供三种方式获得数据:内存传入、HTTP传入、跨域传入。我这里所讲是内存传入Ext.data.MemoryProxyvar_store=newExt.data.Store({        proxy:newExt.data.MemoryProxy(_xml.getValue()),        reader:newExt.data.XmlReader({              record:"row"             },Ext.data.Record.create(["name","sex"]))        });           _store.on("load",function(_store){                  alert(_store.getAt(0).getCount());                  });           _store.load(); 摘自:陈治文,非本人原创ExtJS与JSP连接,把数据写入数据库2008年12月17日星期三下午10:49haha使用ExtJS颇有心得,下面的问题本来是我问别人的最后自己搞定了,改自一个与PHP的版本。现在有一个ExtJS做的前台注册窗口,窗口中有用户和密码两栏,一个提交按钮。-----现在,在用户和密码两栏中填入数据,之后点提交按钮,数据通过EXTJS提交到JSP然后写入数据库。要全部的代码:ExtJS(前台部分):<!--首先前台部分使用extjs写一个简单的注册窗口文件名为login.html--><!DOCTYPEhtmlPUBLIC"-//W3C//DTDXHTML1.0Transitional//EN""http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><htmlxmlns="http://www.w3.org/1999/xhtml"><head><metahttp-equiv="Content-Type"content="text/html;charset=utf-8"/><title>extDemo</title><linkrel="stylesheet"type="text/css"href="ext/resources/css/ext-all.css"/><scripttype="text/javascript"src="ext/adapter/ext/ext-base.js"></script><scripttype="text/javascript"src="ext/ext-all.js"></script></head><body><script>Ext.onReady(function(){         //使用表单提示         Ext.QuickTips.init();         Ext.form.Field.prototype.msgTarget='side';                                  //定义表单         varsimple=newExt.FormPanel({                               labelWidth:75,                                                       baseCls:'x-plain',                               defaults:{width:150},                               defaultType:'textfield',//默认字段类型                                               //定义表单元素                               items:[{                                               fieldLabel:'帐户',                                               name:'name',//元素名称                                               //anchor:'95%',//也可用此定义自适应宽度                                               allowBlank:false,//不允许为空                                               blankText:'帐户不能为空'//错误提示内容                                       },{                                           inputType:'password',                                               fieldLabel:'密码',                                               //anchor:'95%',                                               name:'pws',                                               allowBlank:false,                                               blankText:'密码不能为空'                                       }                               ],                               buttons:[{                                       text:'提交',                                       type:'submit',                                       //定义表单提交事件                                       handler:function(){                             if(simple.form.isValid()){//验证合法后使用加载进度条                                                             Ext.MessageBox.show({                                                                          title:'请稍等',                                                                          msg:'正在加载...',                                                                          progressText:'',                                                                          width:300,                                                                          progress:true,                                                                          closable:false,                                                                          animEl:'loding'                                                                  });                                                                  //控制进度速度                                                                  varf=function(v){                                                                        returnfunction(){                                                                                               vari=v/11;                                                                                               Ext.MessageBox.updateProgress(i,'');                                                                           };                                                                  };                                                                  for(vari=1;i<13;i++){                                                                               setTimeout(f(i),i*150);                                                                  }                                                                                                  //提交到服务器操作                                                                 simple.form.doAction('submit',{                                                                        url:'check.jsp',//文件路径                                                                        method:'post',//提交方法post或get                                                                        params:'',                                                                        //提交成功的回调函数                                                                        success:function(form,action){                                                                                       if(action.result.msg=='ok'){                                                                                               //document.location='index.html';                                                                                               Ext.Msg.alert('提示窗口','提交已成功!');                                                                                       }else{                                                                                               Ext.Msg.alert('登陆错误',action.result.msg);                                                                                       }                                                                        },                                                                        //提交失败的回调函数                                                                        failure:function(){                                                                                       Ext.Msg.alert('错误','服务器出现错误请稍后试!');                                                                        }                                                                 });                                                          }                                                                                                                     }                               },{                                       text:'取消',                                       handler:function(){simple.form.reset();}//重置表单                               }]                       });                                 //定义窗体                                  win=newExt.Window({                                               id:'win',                                               title:'注册窗口',                                               layout:'fit',  //之前提到的布局方式fit,自适应布局                                                                                  width:300,                                               height:150,                                               plain:true,                       bodyStyle:'padding:5px;',                                               maximizable:false,//禁止最大化                                               closeAction:'close',                                               closable:false,//禁止关闭                                               collapsible:true,//可折叠                                               plain:true,                                               buttonAlign:'center',                                               items:simple//将表单作为窗体元素嵌套布局                                       });                                       win.show();//显示窗体                                                                                               });</script></body></html>JSP(后台部分)代码:<!--后台部分这里数据库使用的是Access数据库   本文件名为check.jsp--><%@pagelanguage="java"contentType="text/html;charset=gb2312"   pageEncoding="gbk"%><%@pageimport="java.sql.*,java.util.*"%><%     request.setCharacterEncoding("gb2312");     Stringname=request.getParameter("name");     Stringpws=request.getParameter("pws");     if(name.equals(pws)){        out.print("{success:true,msg:\'ok\'}");     }else{        out.print("{success:true,msg:\'帐户或密码错误\'}");     }          try{     Stringmessage=pws;     StringsourceURL="jdbc:odbc:driver={MicrosoftAccessDriver(*.mdb)};DBQ=D://accdb";    //DataBase是AccessMDB文件的主文件名     try{           Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");           }catch(Exceptione){            e.printStackTrace();        }     Connectionconn=DriverManager.getConnection(sourceURL);//把驱动放入连接     Statementstmt=conn.createStatement();//创建一个Statement对象来将SQL语句发送到数据库。     stmt.executeUpdate("INSERTINTOstudentVALUES("+"'"+name+"'"+","+"'"+message+"'"+")");         stmt.close();     conn.close();   }   catch(SQLExceptionsqle){           //System.err.println(sqle);   }     %>

Extjs如何与数据库交互.doc

Extjs如何与数据库交互.doc

上传者: zhangpeng2084
640次下载 0人收藏 暂无简介 简介 2011-12-25 举报

简介:extjs

一般需要添加一组数据,引入一个概念 Ext.data.Reader, 这里的 Reader 功能非常单一,只 是用来解析数据的到, EXTJS 支持不同的数据格式,也就需要不同的数据解析器。而这个 Reader 就是承担解析器的作用。 1 、数组形式数据解析(特殊的 JSON 形式数据,因此, ArrayReader JsonReader 的子 类) var_store=newExt.data.Store({ data:[[" 陈治文 "," "],[" 张妍娜 "," "]], reader:newExt.data.ArrayReader({ },Ext.data.Record.create(["name","sex"])) }); 解析器为 ArrayReader ,分别解析 [" 陈治文 "," "] [" 张妍娜 "," "] ,将其转换成 Ext.data.Record 2 JSON 形式数据 var_store=newExt.data.Store({ data:[{name:" 陈治文 ",sex:" "},{name:" 张妍娜 ",sex:" "}], reader:newExt.data.JsonReader({ },Ext.data.Record.create(["name","sex"])) }); alert(_store.getCount()); JsonReader 分别解析 {name:" 陈治文 ",sex:" "} {name:" 张妍娜 ",sex:" "} ,将这些数 据解析成 Ext.data.Record 类型数据 3 XML 形式数据 这里的有个地方比较麻烦,首先,我们必须得构建一个XML Document ,这样才能形成X ML数据,我们这里所讲的是ASP Server 的XML组织形式

第1页

相关资料推荐

  • 名称/格式
  • 下载次数
  • 资料大小

用户评论

0/200
暂无评论
上传我的资料

资料阅读排行

该用户的其它资料

关闭

请选择举报的类型

关闭

提示

提交成功!

感谢您对爱问共享资料的支持,我们将尽快核实并处理您的举报信息。

关闭

提示

提交失败!

您的举报信息提交失败,请重试!

关闭

提示

重复举报!

亲爱的用户!感觉您对爱问共享资料的支持,请勿重复举报噢!

全屏 缩小 放大
收藏
资料评价:

/ 7
所需积分:0 立即下载
返回
顶部
举报
资料
关闭

温馨提示

感谢您对爱问共享资料的支持,精彩活动将尽快为您呈现,敬请期待!