Struts1.2.4学习心得!(四)

2023-10-15 10:08
文章标签 学习心得 struts1.2

本文主要是介绍Struts1.2.4学习心得!(四),希望对大家解决编程问题提供一定的参考价值,需要的开发者们随着小编来一起学习吧!

第四次学习:

这次学习碰到了与struts1.1很不同的地方,就是ActionForm类不仅仅是String型,可以是任意数据类型了.

1.表单录入(含bean的嵌套).

设有一个testBean类,这个类中又含有一个nested属性(nested为一个类的实例),当要为nested类的booleanProperty属性设定值时用nested.booleanProperty指定位置.下面例子录入数据时,数据填充到testBean和nested中去.

java代码:

1
2<%@ taglib uri="/tags/struts-bean" prefix="bean" %>
3<%@ taglib uri="/tags/struts-html" prefix="html" %>
4<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
5<html:html>
6 <head>
7 <title>Test struts-html Property Setters</title>
8 </head>
9 <body>
10 <div align="center">
11 <h1>Test struts-html Property Setters</h1>
12 </div>
13 <p>Whatever changes you make to properties should be reflected when the page is redisplayed. Press "Save" to update, or "Cancel" to return to the main menu.</p>
14 <html:form action="/html-setters-submit">
15 <table border=" 0" width=" 100%">
16 <tr>
17 <th align="center" colspan=" 4">Scalar Properties</th>
18 </tr>
19 <tr>
20 <th align="right">booleanProperty</th>
21 <td align="left">
22 <html:checkbox property="booleanProperty" />
23 </td>
24 <th align="right">nested. booleanProperty</th>
25 <td align="left">
26 <html:checkbox property="nested. booleanProperty" />
27 </td>
28 </tr>
29 <tr>
30 <th align="right">doubleProperty</th>
31 <td align="left">
32 <html:text property="doubleProperty" size=" 32" />
33 </td>
34 <th align="right">nested. doubleProperty</th>
35 <td align="left">
36 <html:text property="nested. doubleProperty" size=" 32" />
37 </td>
38 </tr>
39 <tr>
40 <th align="right">floatProperty</th>
41 <td align="left">
42 <html:text property="floatProperty" size=" 32" />
43 </td>
44 <th align="right">nested. floatProperty</th>
45 <td align="left">
46 <html:text property="nested. floatProperty" size=" 32" />
47 </td>
48 </tr>
49 <tr>
50 <th align="right">intProperty</th>
51 <td align="left">
52 <html:text property="intProperty" size=" 32" />
53 </td>
54 <th align="right">nested. intProperty</th>
55 <td align="left">
56 <html:text property="nested. intProperty" size=" 32" />
57 </td>
58 </tr>
59 <tr>
60 <th align="right">longProperty</th>
61 <td align="left">
62 <html:text property="longProperty" size=" 32" />
63 </td>
64 <th align="right">nested. longProperty</th>
65 <td align="left">
66 <html:text property="nested. longProperty" size=" 32" />
67 </td>
68 </tr>
69 <tr>
70 <th align="right">stringProperty</th>
71 <td align="left">
72 <html:text property="stringProperty" size=" 32" />
73 </td>
74 <th align="right">nested. stringProperty</th>
75 <td align="left">
76 <html:text property="nested. stringProperty" size=" 32" />
77 </td>
78 </tr>
79 <tr>
80 <th align="center" colspan=" 4">Indexed Properties</th>
81 </tr>
82 <tr>
83 <th align="right">intIndexed [ 0 ]</th>
84 <td align="left">
85 <html:text property="intIndexed [ 0 ]" size=" 32" />
86 </td>
87 <th align="right">nested. intIndexed [ 0 ]</th>
88 <td align="left">
89 <html:text property="nested. intIndexed [ 0 ]" size=" 32" />
90 </td>
91 </tr>
92 <tr>
93 <th align="right">intIndexed [ 1 ]</th>
94 <td align="left">
95 <html:text property="intIndexed [ 1 ]" size=" 32" />
96 </td>
97 <th align="right">nested. intIndexed [ 1 ]</th>
98 <td align="left">
99 <html:text property="nested. intIndexed [ 1 ]" size=" 32" />
100 </td>
101 </tr>
102 <tr>
103 <th align="right">stringIndexed [ 0 ]</th>
104 <td align="left">
105 <html:text property="stringIndexed [ 0 ]" size=" 32" />
106 </td>
107 <th align="right">nested. stringIndexed [ 0 ]</th>
108 <td align="left">
109 <html:text property="nested. stringIndexed [ 0 ]" size=" 32" />
110 </td>
111 </tr>
112 <tr>
113 <th align="right">stringIndexed [ 1 ]</th>
114 <td align="left">
115 <html:text property="stringIndexed [ 1 ]" size=" 32" />
116 </td>
117 <th align="right">nested. stringIndexed [ 1 ]</th>
118 <td align="left">
119 <html:text property="nested. stringIndexed [ 1 ]" size=" 32" />
120 </td>
121 </tr>
122 <tr>
123 <td></td>
124 <td align="right">
125 <html:submit>Save</html:submit>
126 </td>
127 <td align="left">
128 <html:reset>Reset</html:reset>
129 <html:cancel>Cancel</html:cancel>
130 </td>
131 <td></td>
132 </tr>
133 </table>
134 </html:form>
135 </body>
136</html:html>
137
138



对应的TestBean


java代码:copy.gif

1
2 /*
3 * $Header: /home/cvs/jakarta-struts/src/examples/org/apache/struts/webapp/exercise/TestBean.java,v 1.4 2004/03/14 06:23:52 sraeburn Exp $
4 * $Revision: 1.4 $
5 * $Date: 2004/03/14 06:23:52 $
6 *
7 * Copyright 1999-2004 The Apache Software Foundation.
8 *
9 * Licensed under the Apache License, Version 2.0 (the "License");
10 * you may not use this file except in compliance with the License.
11 * You may obtain a copy of the License at
12 *
13 * http://www.apache.org/licenses/LICENSE-2.0
14 *
15 * Unless required by applicable law or agreed to in writing, software
16 * distributed under the License is distributed on an "AS IS" BASIS,
17 * WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
18 * See the License for the specific language governing permissions and
19 * limitations under the License.
20 */

21
22
23 package org. apache. struts. webapp. exercise;
24
25
26 import java. util. ArrayList;
27 import java. util. Collection;
28 import java. util. HashMap;
29 import java. util. List;
30 import java. util. Map;
31 import java. util. Vector;
32 import javax. servlet. http. HttpServletRequest;
33 import org. apache. struts. action. ActionForm;
34 import org. apache. struts. action. ActionMapping;
35 import org. apache. struts. util. LabelValueBean;
36
37
38 /**
39 * General purpose test bean for Struts custom tag tests.
40 *
41 * @version $Revision: 1.4 $ $Date: 2004/03/14 06:23:52 $
42 */

43
code.gif 44 public class TestBean extends ActionForm {
...}
45
46
47 // ------------------------------------------------------------- Properties
48
49
50 /**
51 * A collection property where the elements of the collection are
52 * of type <code>LabelValueBean</code>.
53 */

54 private Collection beanCollection = null;
55
code.gif 56 public Collection getBeanCollection ( ) {
...}
code.gif 57 if (beanCollection == null ) {
...}
58 Vector entries = new Vector ( 10 );
59
60 entries. add ( new LabelValueBean (" Label 0", "Value 0" ) );
61 entries. add ( new LabelValueBean (" Label 1", "Value 1" ) );
62 entries. add ( new LabelValueBean (" Label 2", "Value 2" ) );
63 entries. add ( new LabelValueBean (" Label 3", "Value 3" ) );
64 entries. add ( new LabelValueBean (" Label 4", "Value 4" ) );
65 entries. add ( new LabelValueBean (" Label 5", "Value 5" ) );
66 entries. add ( new LabelValueBean (" Label 6", "Value 6" ) );
67 entries. add ( new LabelValueBean (" Label 7", "Value 7" ) );
68 entries. add ( new LabelValueBean (" Label 8", "Value 8" ) );
69 entries. add ( new LabelValueBean (" Label 9", "Value 9" ) );
70
71 beanCollection = entries;
72 }
73
74 return (beanCollection );
75 }
76
code.gif 77 public void setBeanCollection ( Collection beanCollection ) {
...}
78 this. beanCollection = beanCollection;
79 }
80
81
82 /**
83 * A multiple-String SELECT element using a bean collection.
84 */

85 private String [ ] beanCollectionSelect = { "Value 1", "Value 3",
86 "Value 5" };
87
code.gif 88 public String [ ] getBeanCollectionSelect ( ) {
...}
89 return (this. beanCollectionSelect );
90 }
91
code.gif 92 public void setBeanCollectionSelect ( String beanCollectionSelect [ ] ) {
...}
93 this. beanCollectionSelect = beanCollectionSelect;
94 }
95
96
97 /**
98 * A boolean property whose initial value is true.
99 */

100 private boolean booleanProperty = true;
101
code.gif 102 public boolean getBooleanProperty ( ) {
...}
103 return (booleanProperty );
104 }
105
code.gif 106 public void setBooleanProperty ( boolean booleanProperty ) {
...}
107 this. booleanProperty = booleanProperty;
108 }
109
110
111 /**
112 * A multiple-String SELECT element using a collection.
113 */

114 private String [ ] collectionSelect = { "Value 2", "Value 4",
115 "Value 6" };
116
code.gif 117 public String [ ] getCollectionSelect ( ) {
...}
118 return (this. collectionSelect );
119 }
120
code.gif 121 public void setCollectionSelect ( String collectionSelect [ ] ) {
...}
122 this. collectionSelect = collectionSelect;
123 }
124
125
126 /**
127 * A double property.
128 */

129 private double doubleProperty = 321. 0;
130
code.gif 131 public double getDoubleProperty ( ) {
...}
132 return (this. doubleProperty );
133 }
134
code.gif 135 public void setDoubleProperty ( double doubleProperty ) {
...}
136 this. doubleProperty = doubleProperty;
137 }
138
139
140 /**
141 * A boolean property whose initial value is false
142 */

143 private boolean falseProperty = false;
144
code.gif 145 public boolean getFalseProperty ( ) {
...}
146 return (falseProperty );
147 }
148
code.gif 149 public void setFalseProperty ( boolean falseProperty ) {
...}
150 this. falseProperty = falseProperty;
151 }
152
153
154 /**
155 * A float property.
156 */

157 private float floatProperty = (float ) 123. 0;
158
code.gif 159 public float getFloatProperty ( ) {
...}
160 return (this. floatProperty );
161 }
162
code.gif 163 public void setFloatProperty (float floatProperty ) {
...}
164 this. floatProperty = floatProperty;
165 }
166
167
168 /**
169 * Integer arrays that are accessed as an array as well as indexed.
170 */

171 private int intArray [ ] = { 0, 10, 20, 30, 40 };
172
code.gif 173 public int [ ] getIntArray ( ) {
...}
174 return (this. intArray );
175 }
176
code.gif 177 public void setIntArray ( int intArray [ ] ) {
...}
178 this. intArray = intArray;
179 }
180
181 private int intIndexed [ ] = { 0, 10, 20, 30, 40 };
182
code.gif 183 public int getIntIndexed ( int index ) {
...}
184 return (intIndexed [index ] );
185 }
186
code.gif 187 public void setIntIndexed ( int index, int value ) {
...}
188 intIndexed [index ] = value;
189 }
190
191
192 private int intMultibox [ ] = new int [ 0 ];
193
code.gif 194 public int [ ] getIntMultibox ( ) {
...}
195 return (this. intMultibox );
196 }
197
code.gif 198 public void setIntMultibox ( int intMultibox [ ] ) {
...}
199 this. intMultibox = intMultibox;
200 }
201
202 /**
203 * An integer property.
204 */

205 private int intProperty = 123;
206
code.gif 207 public int getIntProperty ( ) {
...}
208 return (this. intProperty );
209 }
210
code.gif 211 public void setIntProperty (

这篇关于Struts1.2.4学习心得!(四)的文章就介绍到这儿,希望我们推荐的文章对编程师们有所帮助!



http://www.chinasem.cn/article/216984

相关文章

Java EE学习心得

–Java EE学习心得     1.    称为编程专家的秘诀是: 思考-----编程--------思考------编程…….. 编程不能一步到位,不能一上来就编,必须先思考如何写,怎样写?然后再编程,完事后,再思考  我编的程序还有那些不好的地方和要改进的地方,可以增加写什么功能等等;然后再去编程; 2. 先搭建整体框架再抠细节,在编程中不管是什么要先做出来,再去问怎么做!即是:先K

24.9.1学习心得

VGG(Visual Geometry Group)网络是由牛津大学视觉几何小组提出的一种卷积神经网络模型,该模型因其在ImageNet大规模视觉识别挑战赛(ILSVRC 2014)中的优异表现而闻名。VGG模型的特点在于其架构的简单性和一致性,以及对参数数量的大量使用,这使得它成为了深度学习领域中一个非常受欢迎的基础模型。 VGG架构的主要特点包括: 堆叠的3x3卷积层:VGG网络使用了多

城市管理违规行为智能识别 Task3学习心得

本次学习主要针对数据集增强和模型预测 1、数据增强: 1)将四张训练图像组合成一张,增加物体尺度和位置的多样性。 2)复制一个图像的随机区域并粘贴到另一个图像上,生成新的训练样本 3)图像的随机旋转、缩放、平移和剪切,增加对几何变换的鲁棒性 4)通过线性组合两张图像及其标签创造合成图像,增加特征空间的泛化 5)一个支持多种增强技术的图像增强库,提供灵活的增强管道定义 6)对图像的色相

Datawhale X 李宏毅苹果书 AI夏令营_深度学习基础学习心得Task2.2

本次学习分类问题 1、分类与回归: 回归一般输出一个值y_hat 期望与y越接近越好。分类一般有几类就输出几个值,是一个one-hot的向量,在类别对应的位置值为1 本文介绍了一种重复输出数值后加权的方法,但是我做分类一般用全连接层直接输出多个值,然后使用argmax函数 2、softmax: 公式: 其实主要是一个归一化的作用,并且输出所有值的和为1,这样就类似于每一个类别的概率;并

【60天备战2024年11月软考高级系统架构设计师——第0天:详细规划与学习心得】

开篇 2024年11月的软考高级系统架构设计师考试即将到来,留给我们的时间不多了。在这60天的时间里,我决定全力以赴,通过系统的学习和高效的复习,争取在考试中取得理想的成绩(必拿下)。这篇博客将分享我为备考制定的详细学习计划,以及如何在紧张的时间里高效学习。 第一部分:备考规划概述 要在两个月内通过高级系统架构设计师考试,合理的学习计划是关键。我将整个备考过程划分为四个阶段:基础知识复习、重

Datawhale X 李宏毅苹果书 AI夏令营_深度学习基础学习心得Task2

本次学习主要针对自适应学习率;介绍了Adagrad,RMSprop和Adam优化器 1、为什么需要自适应学习率: 训练一个网络,在走到临界点的时候损失不再下降,而梯度并没有变得很小。相当于下坡路在两步之间,而步子迈大了,直接把下坡路跳过了,又走到上坡路上了。在这时候就需要把学习率(步幅)调低一点让梯度继续下降。 但是常规的 学习率下降方法是不够用的,我们希望在梯度大的时候走慢点,在梯度小的时

24.8.26学习心得

验证数据集(Validation Set)和测试数据集(Test Set)在机器学习和深度学习中都是非常重要的概念。它们各自有不同的用途和目的。下面详细解释两者之间的区别: 1. 验证数据集(Validation Set) 目的: 超参数调整:验证数据集主要用于调整模型的超参数,如学习率、正则化系数、网络层数等。模型选择:用于选择最佳模型。例如,在交叉验证中,通过在验证数据集上的表现来选择性

Datawhale X 李宏毅苹果书 AI夏令营_深度学习基础学习心得

本次学习了深度学习中的局部最小值 1、书上说有时候模型一开始就训练不起来,不管怎么更新参数损失都不下降。我之前遇到过这种情况,大概是做一个数据很不平衡的二分类,正负样本比例大概为9:1,模型倾向于全部预测为正样本,没有办法学习负样本。 2、3.1.1介绍了一下鞍点,鞍点的各个方向的梯度是等于零的,而我们的模型反向传播又是基于梯度的,所以到了鞍点就没有办法再让损失下降了,但是其实鞍点和局部最优又

PSO算法学习心得

一 算法基本思想    粒子群优化算法属于群智能(swarm intelligence)优化算法。群智能分两种,一种是粒群优化,一种是蚁群优化。        群智能概念:假设你和你的朋友们(individual)去寻宝(objective),每个人都有一个探测器(function)可以知道宝藏到探测器的距离。在找的过程中,每个人都可以把信息共享出去,每个人都能看到现在谁离宝藏最近。这样,你看

Spring学习心得

最近有人问我学习Spring的经验。心中不免有些惭愧,本来以为自己对Spring算比较精通啦,但最近看Professional Java development with SpringFramework,发现其实自己还有好多东西不知道。不过既然有人问起,就大概谈一下体会吧,由于我自己的途径与下面所列的步骤还是有些差距的(主要是当时关于Spring的书和参考资料太少了),而且每个人的学习方式也会不