Unmi's Struts2 Learning notes (eight)

Source: Internet
Author: User
Tags definition expression tld

I went to the temple with the same number, but never lit a column of incense. In the spirit of the world is not the end of sustenance. Do not make a living or a woman, and do not need to be blessed with a sacred conscience. If you want something, Amitabha will not give it. In the run-up to soaring prices, who can give you a raise, how to democracy, see if this life can have the opportunity to participate in the election of a national leader, less to say a few words, this is the freedom of speech.

1. The Struts 2 tag library is based on an OGNL expression and is more accessible to collections and objects. Struts 2 is labeled with a uniform prefix, typically "s", and is no longer a label for multiple namespaces like Struts1

2. STRUTS2 offers a number of things that Struts1 tags don't have, such as calendars, tree controls, Tab pages, and DWR, with tags to support Ajax, as well as themes, templates, and custom components in the page. The STRUTS2 tag is defined in a namespace with a "/struts-tags" URI, and the STRUTS2 tag library is powerful and simpler to use.

3. Compared with Struts1, STRUTS2 's tag library does not rely on the presentation technology, that is, most tags, not only used in JSP, but also in the Velocity and Freemarker templates. To support EL in Struts1, the Struts-el.jar and JSTL class libraries must be introduced, while Struts2 default supports OGNL, JSTL, Groovy, and Velocity expressions.

The 4.STRUTS2 label definition file is struts-tags.tld in the Meta-inf directory of Struts2-core-2.x.x.jar. Compared to the Struts1 label definition is in the Struts.jar meta-inf/tld directory of Struts-bean.tld, STRUTS-HTML.TLD, etc. (Struts1 starting from 1.3, the package is also divided into struts-core-1. 3.x.jar and Struts-taglib-1.3.x.jar, so struts-bean.tld, Struts-html.tld, and so on Struts-taglib-1.3.x.jar in the META-INF/tld directory.

5. The application of the servlet 2.4 begins to recursively search for the TLD file loading under Classpath at startup, and the Servlet 2.3 application appears to automatically search for the TLD file load under the Web-inf directory at startup, before the servlet version must be Add <taglib> to the Web.xml file to specify the TLD.

6. Xwork has increased support for valuestack on the basis of the original OGNL. The Struts2 Stack context requires multiple "root" objects, where Valuestack is just one of several "root" objects. If the property you want to access belongs to the root object, you can access the property directly, otherwise you must use a namespace, such as #bar.

Valuestack is a Com.opensymphony.xwork2.util.OgnlValueStack object that has a property name of "Struts.valuestack" in the request.

7. In Struts2, the valuestatck of the system is the first root object (key=com.opensymphony.xwork2.util.valuestack.valuestack) of the OGNL expression, if the most recent Action exists , the action context is the second root object (Key=com.opensymphony.xwork2.actioncontext.name, just the name of the action). The stack contenxt and value stack Contents can be displayed with <s:debug/>.

8. The standard OGNL expression is: "#" to start from the root, such as request is a root

<s:property value = "#request [' Struts.request_uri ']"/> Output the URI of the current request, because "Struts.request_uri" contains ".", or it can be used #reques The form of t.xxx.

If, as a property name, it is the Name property of the root object, but Struts2 will have multiple root objects, it will be ambiguous, so this time <s:property value= "${name}"/> accesses the object's property name in Valuestack --Valuestack is a root object of a OGNL expression.

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.