Struts Development Guide-a preliminary understanding of Taglib

Source: Internet
Author: User
Tags i18n

TAGLIB
  
Struts extends Taglib. Struts provides four basic custom Taglib types and two additional Taglib types:
  
Bean: struts-bean taglib contains the tags used to access bean and bean attributes, and also contains tags for message display.
  
Html: struts-html taglib contains tags used to create struts input forms, and other tags used to create HTML-based user interfaces.
  
Logic: the tag contained in struts-logic taglib is used to manage output text generated based on conditions, and other information used for control.
  
Template: The tag contained in struts-template taglib is used to define the template mechanism.
  
Tiles: Tiles plug-in, used to simplify jsp development
  
Nested: The Role of the Nested tag library is to enable the above basic tag library to be nested for use, play a greater role.
  
Using taglib can simplify jsp page development and make jsp contain the least code.
  
For example, during JSP development, the virtual directory is relative to the Domain. If http: // localhost/context1/test. when jsp executes href = "/", it returns http: // localhost/. How does one return http: // localhost/context1? In this way, you can use   
I18n support
  
To display a set of interfaces that support i18n, you must first define an ApplicationResource file and put the information in the form of key = value. By specifying the resouces address in the struts-config.xml, you can use a tag such as <bean: message key = "welcome"> to display it without curing the information in the JSP file.
  
TILES:
  
Tiles divides pages like TDK in another project Turbine of jakarta. Added the concept of layout.
  
In fact, a page is divided into several parts. Generally, a page can be divided into the following parts:
  
Head page header: stores a Public Information used: logo, etc. If it is a website, it may be the top one.
  
Menu page menu: place a menu to be used, or connect to each page.
  
Footer page tail: such as copyright information.
  
Body page topic content: relatively independent content of each page.
  
If we use the above division, we only need to write the content in the body for each page, and other content can be shared and reused.
  
If the layout of most pages is basically the same, we can even use a jsp file to call different bodies according to different parameters.
  
In addition to the basic Template function, Tiles also provides layout definition, virtual page definition, dynamic page generation, and other functions.
  
The powerful template function of Tiles can maximize the reusability and flexibility of pages. In addition, it can combine the page definition in the Tiles configuration file and the Action forwarding logic, that is, you can forward an Action to a virtual page defined in the Tiles configuration file to reduce the number of pages. For example, the Action in the following table defines a forwarding path, whose end point is tile. userMain, and the latter is a page defined in the Tiles configuration file.
  
EXCEPTION
  
Exception Handling is well supported in Struts1.1
  
You can specify in the configuration file who will handle an exception thrown in the Action class. Follow these steps:
  
1. Implement the subclass of org. apache. struts. action. ExceptionHandler, overwrite the execute method, handle exceptions in this method, and return an ActionForward object
  
2. Configure an exception handling object in the configuration file. You can configure a global processing class or configure a processing class for each Action separately.
  
The following table defines a global processing class CustomizedExceptionHandler, which is used to handle all exceptions.
  
<Global-exceptions>
<Exception
Handler = "com. yourcorp. CustomizedExceptionHandler"
Key = "global. error. message"
Path = "/error. jsp"
Scope = "request"
Type = "java. lang. Exception"/>
</Global-exceptions>

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.