"Web Development Learning Note" Struts-tags Learning Note 1-Universal label and Control label

Source: Internet
Author: User
Tags access properties control label set set

General label and Control label the first part; code
Front 
Struct.xml<constant name= "Struts.ui.theme" value= "simple"/><package name= "tags" extends= "struts-default "><action name=" tags "class=" com.struts2.tags.TagsAction "><result>/tags.jsp</result></ Action></package>
//Class pack Package Com.struts2.tags;import Com.opensymphony.xwork2.actionsupport;public class Tagsaction extends ActionSupport {private String Password;private string Username;public tagsaction () {}public string execute () {This.addfielderror (" Fielderror.test "," wrong! "); return SUCCESS;} Public String GetPassword () {return password;} Public String GetUserName () {return username;} public void SetPassword (String password) {this.password = password;} public void Setusername (String username) {this.username = username;}} 
Show Part II: AnalysisFront End: <a href= "<%=contextpath%>/tags.action?username=u&password=p" >tags</a> after click  , passed on to
Tag.action two parameters of username and password.
-Struct.xml configuration, invokes the Tagsaction.java class, initializes the object, and sets the initial value on the object.
<package name= "tags" extends= "struts-default" ><action name= "tags" class= "com.struts2.tags.TagsAction" > <result>/tags.jsp</result></action></package>
based on the result information of the Struct.xml configuration, the results are passed to the tag.jsp shown in the description in the <result>/tags.jsp</result>
Row value operation;
Part III: General label operations
Property Tags: <li>property: <s:property value= "username"/> </li><li>property value as a string: <s: Property value= "' username '"/> </li><li>property set Default value: <s:property value= "admin" default= "admin"/ > </li><li>property Set HTML: <s:property value= "' 
Analysis:
The property takes a value of string: <s:property value= "' username '"/> when the value in S:proerty in a label is double-quoted with a single quote, the table
The value inside the single quotation mark is treated as a string.
set label:< Li>set Set AdminName value (default to request and Actioncontext): <s:set var= "AdminName" value= "username"/></li><li >set from Request: <s:property value= "#request. AdminName"/></li><li>set value from Actioncontext: <s: Property value= "#adminName"/></li><s:debug></s:debug><li>set set Var with a range of Actioncontext: <s:set var= "AdminPassword" value= "password" scope= "session"/></li><li>set use # Value: <s:property Value= "#adminPassword"/> </li><li>set value from the corresponding range: <s:property value= "#session. AdminPassword"/> </li> 
Analysis:
The scope value can be set inside the set: scope
Scope defaults to action and can be achieved with five scopes: the scope in which to assign the variable. Can be application,
session, request, page, or action.
Bean tag: <li>bean defines the bean and uses Param to set the new property value: <s:bean name= "Com.struts2.tags.Dog" ><s:param name= "name" Value= "' pp '" ></s:param><s:property value= "name"/></s:bean></li><li>bean View Debug conditions: <s:bean name= "Com.struts2.tags.Dog" var= "Mydog" ><s:param name= "name" value= "' Oudy '" ></s: Param></s:bean> out value: <s:property value= "#myDog. Name"/></li>
Analysis:
Bean label
The type of the parameter name is string, and the function is the class name of the bean to be instantiated (must respect JavaBean
Specification), define a class that needs to be instantiated.
The method of the value: All start with #, which variable name is the guy
#adminPassword
#session. AdminPassword
#myDog. Name
Notice the two different ways:
<s:bean name= "Com.struts2.tags.Dog" >
When the S:bean execution begins, an object is constructed to stack to the top of the stack and removed from the top of the stack after execution.
<s:bean name= "Com.struts2.tags.Dog" var= "Mydog" >
Put in stack Context after execution
Include tag <s:set var= "Incpage" value= "%{'/_include1.html '}"/><s:include value= "%{#incPage}" ></s: Include>
%{} effect: Force it to OGNL expression;
Part IV: Control label operation
set a short name through set;
Part V: Traversing tags
<li> Traversal collection: <br/><s:iterator value= "{1, 2, 3}" ><s:property/> |</s:iterator></li> <li> Custom variables: <br/><s:iterator value= "{' AAA ', ' BBB ', ' CCC '}" var= "x" ><s:property value= "# X.touppercase () "/> |</s:iterator></li>
Analysis: String collection, var = "X" is equivalent to the temporary variable defined in the For loop, each value in the collection is taken out, and the value is placed in X once per loop. Use # to access it.
<li> using status:<br/><s:iterator value= "{' AAA ', ' BBB ', ' CCC '} ' status= ' status ' ><s:property/> | Total number of traversed elements: <s:property value= "#status. Count"/> | traversed element index: <s:property value= "#status. Index"/> | is currently an even number? : <s:property value= "#status. even"/> | is currently an odd number? : <s:property value= "#status. Odd"/> | is the first element? : <s:property value= "#status. First"/> | Is this the last element? : <s:property value= "#status. Last"/><br/></s:iterator></li>
Analysis: Status action if specified, an instanceof Iteratorstatus'll be pushed to stack upon each iteration
S:property Remove the current value of the loop. To get the loop condition by taking the status value

<li><s:iterator value= "#{1: ' A ', 2: ' B ', 3: ' C '}" ><s:property value= "key"/> | <s:property value= "value"/> <br/></s:iterator></li><li><s:iterator value= "#{1: ' A ', 2: ' B ', 3: ' C '} "var=" x "><s:property value=" #x. Key "/> | <s:property value= "#x. Value"/> <br/></s:iterator></li>
Analysis: When you define a map, you need to precede it with #;

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.