"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

The first part of the Universal label and Control label. 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 stri Ng 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> clicked, passed to
Tag.action two parameters username and password.


-Struct.xml configuration, call 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 <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 the label is a double-argument with a single-quote, the table
The value inside the single argument is treated as a string.
Set tag: <li>set set AdminName value (default feel request and Actioncontext): <s:set var= "AdminName" value= "username"/></li ><li>set value 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. Range is actioncontext: <s:set var= "AdminPassword" value= "password" scope= "session"/></li><li>set use # Value : <s:property value= "#adminPassword"/> </li><li>set from the corresponding range: <s:property value= "# Session.adminpassword "/> </li>
Analysis:
Ability to set scope values within set: scope
There are five scopes that can be achieved by scope: 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 parameter name is of type 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 run starts, an object is constructed to stack to the top of the stack, which is removed from the top of the stack after the run is completed.
<s:bean name= "Com.struts2.tags.Dog" var= "Mydog" >
After running, place the stack Context
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> self-defined 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 get an interview.


<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.

By taking a value for the status. To get the loop condition.

<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 #;

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

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.