Exercise -Struts-Examples1.3.8
l Bean:cookie
取得某个cookie的值
<bean:cookie id="sess" name="JSESSIONID" value="JSESSIONID-IS-UNDEFINED" />
获取名为“JSESSIONID”的cookie,并放入page范围内。
<bean:write name="sess" property="value" />
在页面上打印出cookie的属性
其他方式:
<jsp:getProperty name="sess" property="value" /> javabean标签
<%=((Cookie)(pageContext.getAttribute(“sess”))).getValue()%> pageContext方式
<%=sess.getValue()%> 变量取值的方式
l Bean:define
在page范围内定义一个变量,值从另一个对象的某个简单属性获取
<bean:define id="test1_long" name="test1" property="longProperty" />
可以通过bean:write,jsp:getProperty, <%=test1_long%> 获得定义变量的值
只从另一个嵌套对象的属性获取
<bean:define id="test2_boolean" name="test2" property="nested.booleanProperty" />
l Bean:header
从http请求头定义page范围的变量
<bean:header id="head" name=" Accept-Language"/>
l Bean:include
把一个page内容读入page范围内的一个变量
<bean:include id="welcome" page="/welcome.jsp" />
l Bean:parameter
将一个请求里的参数读入page范围内的一个变量,如果没有参数就抛异常JspException
<bean:parameter id="param1" name="param1"/>
l Bean:page
存储java的隐式对象到page范围内,隐式对象包括:pplication, config, request, response, or session
<bean:page id="cfg" property="config"/>
<bean:write name="cfg" property="servletName"/>
l Bean:resource
将web应用资源读入到page范围内。
<bean:resource id="webxml" name="/WEB-INF/web.xml" />
l Bean:size
将数组,集合,map的大小存入到page范围内
<bean:size id="stringSize" name="bean" property="stringArray" />
l Bean:struts
将struts配置对象,form,forward,mapping对象读入到page范围内
<bean:struts id="cfg" mapping="/search"/>
l Bean:write
渲染一个对象到页面
<bean:write name="test1.float" />
<bean:write name="test2" property="booleanProperty" />
<bean:write name="test3" property="intArray[1]"/>
<bean:write name="test5" property="nested.booleanProperty" />
<bean:write name="test7.double" format="#,000.00" />
<bean:write name="test7.date" formatKey="date.pattern" />
l html:cancel
输出<input type=”submit”>,会触发struts的cancel特征
<html:form action="/html-cancel-false">
<html:submit property="submit"/>
<html:reset/>
<html:cancel/>
</html:form>
与下面action的cancellable属性有关
<action path="/html-cancel-false" name="testbean"
input="/html-cancel.jsp" cancellable="false"validate="true" forward="/welcome.do">
validate为true时,cancellable必须为true,否则有异常
l html:img
输出<img>
<html:img page="/struts-power.gif" />
<html:img action="/html-img-action" />
<html:img page="/exercise/struts-power.gif" module="/"/>
l html:image
输出<input type=”image”>
<html:image page="/struts-power.gif" />
<html:image page="/struts-power.gif" module="/validator"/>
l html:link
输出<a>标签,由基本url加query string构成
<html:link action="/html-link-submit">No modifications at all</html:link>
<html:link action="/html-link-submit?doubleProperty=321.321&longProperty=321321">Double and long via hard coded changes</html:link>
<html:link action="/html-link-submit" paramId="stringProperty" paramName="newValue">String via paramId and paramName</html:link>
<html:link action="/html-link-submit" paramId="booleanProperty" paramName="testbean" paramProperty="nested.booleanProperty">Boolean via paramId, paramName, and paramValue</html:link>
<html:link action="/html-link-submit" name="newValues">Float, int, and stringArray via name (Map)</html:link>
<html:link action="/html-link">
No modifications at all, but link to the default module.
</html:link>
<html:link action="/html-link?doubleProperty=321.321&longProperty=321321"
module="/exercise">
Double and long via hard coded changes (module)
</html:link>
<td colspan="4" align="center">
<html:link action="/html-link"
paramId="stringProperty" paramName="newValue">
String via paramId and paramName
</html:link>
<html:link action="/html-link"
paramId="booleanProperty"
paramName="testbean" paramProperty="nested.booleanProperty"
module="/exercise">
Boolean via paramId, paramName, and paramValue (module)
</html:link>
<html:link action="/html-link"
name="newValues">
Float, int, and stringArray via name (Map)
</html:link>
<html:link forward="relative">module welcome page</html:link>
<html:link action="/welcome" module="/">application welcome page (module="/")</html:link>
l html:multibox
输出<input type=”checkbox”>
<logic:iterate id="item" property="items">
<html:multibox property="selectedItems">
<bean:write name="item"/>
</html:multibox>
<bean:write name="item"/>
</logic:iterate>
l html:rewrite
输出url的字符串,但不做超链接
<html:rewrite href="http://www.yahoo.com/"
paramId="query"
paramName="queryObj"/>
l html:message
打印上下文里Globals.MESSAGE_KEY 对应的一个集合
<html:messages id="msg" property="category">
<li><bean:write name="msg"/></li>
</html:messages>
<html:messages id="msg">
<li><bean:write name="msg"/></li>
</html:messages>
l html:error
打印上下文里Globals.ERROR_KEY 对应的一个集合
<html:errors/>
<html:errors property="username"/>
l logic:equal notEqual
判断= !=
<logic:equal name="bean" property="booleanProperty" value="<%= bool1 %>">equal</logic:equal>
<logic:notEqual name="bean" property="booleanProperty" value="<%= bool1 %>">notEqual</logic:notEqual>
l logic:greaterEqual greaterThan lessEqual lessThan
判断>= > <= <
<logic:greaterEqual name="bean" property="stringProperty" value="<%= str1 %>">greaterEqual</logic:greaterEqual>
<logic:greaterThan name="bean" property="stringProperty" value="<%= str1 %>">greaterThan</logic:greaterThan>
<logic:lessEqual name="bean" property="stringProperty" value="<%= str1 %>">lessEqual</logic:lessEqual>
<logic:lessThan name="bean" property="stringProperty" value="<%= str1 %>">lessThan</logic:lessThan>
l logic:empty notEmpty
判断是否为null或字符串长度为0
<logic:empty name="missingBean">empty</logic:empty>
<logic:notEmpty name="missingBean">notEmpty</logic:notEmpty>
l logic:forward redirect
两种不同的跳转页面方式
<logic:forward name="logic-forward" />
<logic:redirect action="/logic-forward"/>
<logic:redirect forward="logic-forward"/>
<logic:redirect page="/logic-forward.do"/>
注:如果是link的话,由action的forward元素的redirect属性决定
l logic:iterate
迭代一个数组或者集合
<logic:iterate id="element" name="bean" property="stringArray" indexId="index">
<li>
<em>
<bean:write name="element" />
</em> [
<bean:write name="index" />]</li>
</logic:iterate>
l logic:match notMatch
判断是否包含value值
<logic:match cookie="JSESSIONID" value="0">match</logic:match>
<logic:notMatch cookie="JSESSIONID" value="0">notMatch</logic:notMatch>
l logic:present notPresent
判断是否存在,运行包装的内容
<logic:present name="bean">present</logic:present>
<logic:notPresent name="bean">notPresent</logic:notPresent>