In-depth analysis of common tags and themes in JavaWeb Item49 -- Struts2

Source: Internet
Author: User

In-depth analysis of common tags and themes in JavaWeb Item49 -- Struts2
I. Non-UI tags1. property tag

The property tag is used to output the specified value:

* Default: an optional attribute. If the attribute value to be output is null, the specified value is displayed.
* Escape: an optional attribute that specifies whether to format HTML code.
* Value: an optional attribute that specifies the attribute value to be output. If this attribute is not specified, the value at the top of the ValueStack stack is output by default.

2. set tag

The set tag is used to put a value in a specified range.

Var: The variable name, name, id, and var have the same meaning. name and id are replaced by var.
Scope: Specifies the range where variables are placed. This attribute can accept application, session, request, page, or action. If this attribute is not set, it is placed in the context of the value stack by default.
Value: the value assigned to the variable. If this attribute is not set, the value at the top of the ValueStack stack is assigned to the variable.


  




Or:
3. push tag

Push: place the object to the top of the stack. It cannot be in another range. When the Tag ends, it is deleted from the top of the stack.

Value: the value to be pushed to the stack.


       
   
  
Test deletion:
4. bean labels (understanding)

Bean Tag: instantiate a class that complies with the JavaBeans specifications. The TAG body can contain several Param elements and is used to call the setter method to assign values to the attributes of this class.

Name: name of the class to be instantiated (the name must comply with the ANS ans specifications)
Var: the value assigned to the variable. placed in the request scope. If this attribute is not set, the object is placed at the top of the stack.


         
          
   
  
5. action tag

Action: by specifying the namespace and action name, this tag allows you to directly call Action on a jsp page.

Name: action name (excluding suffixes such as. action)
Namespace: namespace where action is located
ExecuteResult: whether the result of the Action needs to be executed. The default value is false.


                     
   
    /ognl/ongl.jsp?msg=${msgxx}
               
     
  
6. iterator label

Iterator: a tag is used to iterate over a Set. The Set here contains List, Set, and array.

Value: an optional attribute that specifies the set to be iterated. If this attribute is not set, the set at the top of the ValueStack stack is used.
Var: Optional attribute, the name of the referenced variable.
Status: an optional attribute that specifies the IteratorStatus instance during iteration. The instance contains the following methods:

Int getCount () returns several elements of the current iteration. Int getIndex () returns the index of the element of the current iteration. Boolean isEven (), returns whether the index of the currently iterated element is an even boolean isOdd (), returns whether the index of the currently iterated element is an odd boolean isFirst (), returns whether the element to be iterated is the first element. Boolean isLast (), returns whether the currently iterated element is the last element.
Action class, which organizes the allList set for (int I = 0; I <10; I ++) {Person p = new Person (); p. setId (I); p. setName ("tom" + I); p. setAge (20 + I); allList. add (p);} ServletActionContext. getRequest (). setAttribute ("allList", allList );
   
  

The attributes of st are in the org. apache. struts2.views. jsp. IteratorStatus class.


  
   
St. getCount ():
   & Nbsp; st. getIndex ():
   & Nbsp; st. isEven ():
   & Nbsp; st. isOdd ():
   & Nbsp; st. isFirst:
   & Nbsp; st. isLast ():
   
   
> // You can use an EL expression.
        
---------------- S: property (emphasis )------------------










---------------- S: set ------------------

---------------- S: push the object to the top of the stack, and then play the stack. to see it, you need to put s: debug inside the tag ------------------

---------------- S: bean ------------------
<% Enumeration e = request. getAttributeNames (); while (e. hasMoreElements () {String name = (String) e. nextElement (); out. write (name + "=" + request. getAttribute (name) +"
") ;}%>
---------------- S: iterator iteration (emphasis )------------------
Name Gender Salary
$ {P. nickname} $ {P. salary}
Name Gender Salary
$ {Nickname} $ {Salary}
">
Name Gender Salary
$ {P. nickname} $ {P. salary}

---------------- S: if else if (important )------------------
Excellent Good Efforts are needed "> Click
Ii. UI tag

The form tag is displayed as a form Element in the HTML document.

Advantages of using form labels:

Form echo layout and layout of pages
Tag attributes can be assigned a static value or an OGNL expression. if an OGNL expression is used during the assignment and it is included in % {}, this expression will be evaluated.

Common attributes of form tags

What are the main labels? Http://www.bkjia.com/kf/ware/vc/ "target =" _ blank "class =" keylink "> history/1bnP1rP2wLQ8L3A + CgoKCjxwcmUgY2xhc3M9" brush: java; "><% @ Page language = "java" import = "java. util. * "pageEncoding =" UTF-8 "%> <% @ taglib uri ="/struts-tags "prefix =" s "%> Use of UI labels

Iii. Themes

Topic: a set of templates that are aggregated to allow all UI labels to produce the same visual effect.Templates with similar styles are packaged as a topic.
1. simple: translate the UI tag into the simplest HTML element, and ignore the row label attribute.
2. xhtml: xhtml is the default topic. The template of this topic provides an automatic typographical mechanism by using a layout table (default)
3. css_xhtml: the templates in this topic are similar to those in the xhtml topic, but they will use css for layout and layout.
4. ajax: the template in this topic is based on the xhtml-themed Reed template, but some Ajax functions are added.

1. Modify the topic:
A. Use the theme attribute of the UI tag (only applicable to the current tag)
  
  

B. in a form, if the theme attribute of a UI tag is not given, it uses the topic of the form.
(Applicable to the entire form tag)

 
  

C. Modify the struts. ui. theme attribute in the struts. properties file (applicable to the entire environment)


  
  

Priority: A> B> C

2. Automatic Display of the struts2 tag

Related Article

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.