日期:2014-05-19  浏览次数:20705 次

j2ee学习struts1.x总结2
******html标记库
1.生成非表单标记
<html:html>
--类似于html中的html标签
<html:base>
--页面中使用了该属性的情况下,在引用同一应用中的其他资源的时候只需要给出相对路径
<html:link {forward=""}|{href=""}|{page=""}>
--使用forward属性,forward给出的是在struts-config中<global-forwards>标签中的<forward>中的name的值
--使用href属性,需要给出完整的utl路径信息
--使用page属性,可以使用相对路径链接到同一个应用的其他页面或者资源,同时还可以通过在rul中拼接参数来实现参数的传递
<html:img page="">
--将page指定的图片加载进来

2.生成表单标记
<html:form path="...">
--path属性值需要和struts-config中的<action>中的path属性值一致
<html:text property="">
--对应html中的文本框
<html:hidden property="" value="">
--对应html中的隐藏表单
<html:checkbox property="***">
--该标记所对应的ActionForm对象的***属性,并且该属性必须是boolean类型的
<html:multibox property="" value="">
--对应html中的复选框
<html:radio property="" value="">
--对应html中的单选框
<html:select>
--格式:
<html:select property="" multiple="true|false" size="">
<html:option value=""></html:option>
<html:option value=""></html:option>
...
</html:select>
--当multiple为true时,下拉列表允许是多选
--size指定了下拉列表同时显示几个列表项
<html:submit>
--<html:submit>提交</html:submit>
<html:reset>
--<html:reset>重置</html:reset>
3.错误信息输出标记<html:errors/>
1>显示错误信息的来源1
ActionErrors errors = new ActionErrors();
errors.add("name",new ActionError("error.name"));
2>编写外部错误信息文件
创建.properties文件,在文件写出键值error.name所对应的值
3>在struts-config中错误信息的文件配置
<message-resources parameter="文件的路径和名称(不包含扩展名)" />
4><html:errors />
--将ActionErrors对象中存放的所有错误信息显示在页面上
5><html:errors property="name" />
--只显示指定名字的错误信息


******bean标记库
1.变量定义标记 <bean:define>
1><bean:define id="v_name" value="v_value" toScope="request" />
--定义request作用域的变量v_name
2><bean:define id="bean2" name="bean1" scope="page" toScope="session" />
--复制page作用域中现有的对象bean1来创建session作用域中新的对象bean2
3><bean:define id="testString" name="bean1" property="name">
--复制现有对象bean1的属性name来创建新的变量testString
2.显示数据标记      
name 指定要显示的数据或者bean的名称
property 如果要显示的数据时bean中的一个属性,则需要指定该属性的名字
scope 设定数据的范围,默认情况下是按照page到application的顺序来搜索的

3.国际化标记 <bean:message/>
用于进行国际化信息输出
1>资源文件中有:
hello.someone=Hello,{0}!
2>在页面中:
<bean:message key="hello.someone" arg0="Tom" />
4.其他标记
<bean:cookie> 用于访问cookie的信息
<bean:header> 用于访问http请求中的header信息
<bean:parameter> 用于访问请求中的参数
<bean:page> 用于访问jsp中的隐式对象
<bean:struts> 用于当问struts框架中内置的对象
<bean:include> 用于包含一个Web资源,类似于<jsp:include>
<bean:size> 用于获取Map或Collection的长度

******logic标记库
1.比较运算符标记
<logic:equal name="" property="" value="">...</logic:equal>
<logic:notEqual name="" property="" value="">...</logic:notEqual>
<logic:greaterEqual name="" property="" value="">...</logic:greaterEqual>
<logic:lessThan name="" property="" value="">...</logic:lessThan>
<logic:greaterThan name="" property="" value="">...</logic:greaterThan>
<logic:lessEqual name="" property="" value="">...</logic:lessEqual>

2.字符串匹配标记
<logic:match name="" value="">...</logic:match>
--判断name指定的变量中是否包含value值