湛江专业建站,wordpress文章展示,晚上必看的正能量直播app,typecho同步到wordpress转自#xff1a;https://yarafa.iteye.com/blog/729197 初学 ExtJS#xff0c;在此记录下学习过程中的点点滴滴#xff0c;以备不时只需#xff0c;也希望能给跟我一样的菜鸟一些帮助#xff0c;老鸟请忽略。如有不当之处#xff0c;欢迎指正。 开发环境#xff1a; MyE…转自https://yarafa.iteye.com/blog/729197 初学 ExtJS在此记录下学习过程中的点点滴滴以备不时只需也希望能给跟我一样的菜鸟一些帮助老鸟请忽略。如有不当之处欢迎指正。 开发环境 MyEclipse 6.5 Struts 2.1.8 ExtJs 3.0 1. 准备工作 首先需要配置 Struts2 和 ExtJS具体操作这里不再多说。 2. 登录页面 1 % page languagejava pageEncodingUTF-8%2 !DOCTYPE html PUBLIC -//W3C//DTD XHTML 1.0 Transitional//EN http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd3 html xmlnshttp://www.w3.org/1999/xhtml4 head5 meta http-equivContent-Type contenttext/html; charsetutf-8 /6 titlelogin Page Test-2/title7 8 !-- 引入ExtJS所需文件--9 link relstylesheet typetext/css hrefjs/extjs/resources/css/ext-all.css /
10 script typetext/javascript srcjs/extjs/adapter/ext/ext-base.js/script
11 script typetext/javascript srcjs/extjs/ext-all.js/script
12 script typetext/javascript
13 var loginForm;
14 Ext.onReady(function() {
15 Ext.BLANK_IMAGE_URL js/extjs/resources/images/default/s.gif;
16 Ext.QuickTips.init();
17
18 // 定义一个 FormPanel 对象
19 loginForm new Ext.FormPanel({
20 width: 400,
21 frame: true,
22 renderTo: loginForm,
23 title: 登录,
24 method: POST,
25 monitorValid: true, // 该属性表示表单在通过验证之前提交按钮无效
26 labelWidth: 50, // 标签宽度
27 labelAlign: left, // 标签的对齐方式
28 labelPad: 0, // 标签与输入框的间隔
29 buttonAlign: center, // 底部按钮居中对齐
30
31 items: [
32 {
33 xtype: textfield,
34 fieldLabel: 用户名,
35 allowBlank: false, // 是否允许为空, 默认为 true
36 blankText: 用户名不能为空, // 显示错误提示信息
37 name: user.username, // name 属性应与 Struts2 Action 中的属性保持一致
38 id: username,
39 width: 300
40 },
41 {
42 xtype: textfield,
43 inputType: password,
44 fieldLabel: 密nbsp;nbsp;nbsp;码,
45 allowBlank: false,
46 blankText: 密码不能为空,
47 name: user.password,
48 id: password,
49 width: 300
50 }
51 ],
52 buttons: [
53 {
54 text: 登nbsp;录,
55 formBind: true,
56 handler: doLogin
57 },
58 {
59 text: 重nbsp;置,
60 handler: doReset
61 }
62 ],
63 keys: [
64 {
65 key: [10, 13],
66 fn: doLogin
67 }
68 ],
69
70 // 表单不使用AJAX方式提交
71 onSubmit: Ext.emptyFn,
72 submit: function() {
73 this.getEl().dom.action login.action;
74 this.getEl().dom.submit();
75 }
76 });
77 });
78
79 // 登录
80 function doLogin() {
81 if(loginForm.form.isValid()) {
82 loginForm.form.submit();
83 }
84 }
85
86 // 重置
87 function doReset() {
88 loginForm.form.reset();
89 }
90 /script
91 /head
92
93 body
94 div idloginForm stylemargin: 100px
95 /div
96 /body
97 /html 页面效果如下图所示 3. Java 类编辑 3.1 User 类 1 /***********************************************************************2 * pProject Name: extjs/p3 * pFile Name: com.thu.afa.extjs.bean.User.java/p4 * pCopyright: Copyright (c) 2010/p5 * pCompany: a hrefhttp://afa.thu.comhttp://afa.thu.com/a/p6 ***********************************************************************/7 package com.thu.afa.extjs.bean;8 9 import java.io.Serializable;
10
11 /**
12 * pClass Name: User/p
13 * pDescription: /p
14 * author Afa
15 * date Aug 4, 2010
16 * version 1.0
17 */
18 public class User implements Serializable
19 {
20 private static final long serialVersionUID 2851358330179740778L;
21
22 private String username;
23 private String password;
24 public String getUsername()
25 {
26 return username;
27 }
28 public void setUsername(String username)
29 {
30 this.username username;
31 }
32 public String getPassword()
33 {
34 return password;
35 }
36 public void setPassword(String password)
37 {
38 this.password password;
39 }
40 } 3.2 Action 类 1 /***********************************************************************2 * pProject Name: extjs/p3 * pFile Name: com.thu.afa.extjs.action.UserAction.java/p4 * pCopyright: Copyright (c) 2010/p5 * pCompany: a hrefhttp://afa.thu.comhttp://afa.thu.com/a/p6 ***********************************************************************/7 package com.thu.afa.extjs.action;8 9 import com.opensymphony.xwork2.ActionSupport;
10 import com.thu.afa.extjs.bean.User;
11
12 /**
13 * pClass Name: UserAction/p
14 * pDescription: /p
15 * author Afa
16 * date Aug 4, 2010
17 * version 1.0
18 */
19 public class UserAction extends ActionSupport
20 {
21 private static final long serialVersionUID 3093253656888703000L;
22
23 private User user;
24
25 public User getUser()
26 {
27 return user;
28 }
29
30 public void setUser(User user)
31 {
32 this.user user;
33 }
34
35 Override
36 public String execute() throws Exception
37 {
38 return (test.equals(user.getUsername()) test.equals(user.getPassword())) ? SUCCESS : INPUT;
39 }
40 } 4. 配置文件 struts.xml 1 ?xml version1.0 encodingUTF-8 ?2 !DOCTYPE struts PUBLIC3 -//Apache Software Foundation//DTD Struts Configuration 2.1.7//EN4 http://struts.apache.org/dtds/struts-2.1.7.dtd5 struts6 package namecom.thu.afa.extjs extendsstruts-default7 action namelogin classcom.thu.afa.extjs.action.UserAction8 result namesuccess/result.jsp/result9 result nameinput/login.jsp/result
10 /action
11 /package
12 /struts 5. 部署运行 开发过程完成部署运行即可。 6. 注意事项 6.1 表单元素的 name 属性 Html代码 name: user.username, // name 属性应与 Struts2 Action 中的属性保持一致 6.2 表单的提交地址 Html代码 this.getEl().dom.action login.action;