Struts principle and application (End)

zhaozj2021-02-11  184

Chapter 7: Taglib and Other Skills

Struts PrinciPle and Practice

TaglibStruts extends Taglib, and Struts provides four basic custom Taglibs and two additional taglib:

Bean: Struts-bean taglib contains Tags used when accessing the bean and bean properties, and also contains some messages displayed TAG. HTML: Struts-HTML Taglib contains Tags used to create a struts input form, and others are typically used to create TAG based on HTML user interfaces. Logic: Struts-logic taglib contains TAGs to manage information generated according to the condition, and some other information used to control. Template: Struts-Template Taglib is included to define a template mechanism. Tiles: TILES plug-in, used to simplify the JSP development NESTED: and the NESTED tag library is to let the above basic tag libraries can be used nested to play a greater role.

Using Taglib can simplify the development of JSP pages so that JSP contains the least code.

For example, in the JSP development process, the virtual directory is relative to Domain. If http: //localhost/context1/test.jsp executes href = "/" will return to http: // localhost /, how to return to http: // localhost / context1 /? This way we can use to locate it relative to the virtual directory.

I18n support If you want to display a set of interfaces that support I18n, first define an ApplicationResource file, put the information in the form of key = value in the form of Key = Value. Specify the address of Resouces in Struts-Config.xml, you can use to cure the information in the JSP file.

Tiles: Tiles Divided into the page of the page with a bit like Jakarta Turbine Turbine. Added the concept of Layout. It is actually divided into a few pieces. Usually, a page can probably be divided into the following: HEAD page header: Store public information: logo, etc. If the website may be the top. Menu Page Menu: Place a use of use. Menu, or connections used in each page. Footer page: such as copyright information, etc. Body page topic content: Each page is relatively independent. If you press the above, we will write to each page. Content, you can share reuse. If most page layouts are basically the same, we can even use a JSP file to call different BODY according to different parameters.

In addition to replacing the basic template feature of the Template, Tiles also adds features such as layout definition, virtual page definition, and dynamic page generation. Tiles powerful template features enable the page to get the maximum reuse and flexibility, and can be combined with page definitions in the Tiles configuration file and the forwarding logic of Action, you can forward an action to a virtual defined in the Tiles configuration file. Page, thereby reducing the number of pages. For example, the action in the table below defines a forwarding path, its endpoint is Tile.userMain, and the latter is a page you defined in the Tiles configuration file.

Exception has been well supported in Struts1.1

You can specify who will handle some anomalies thrown in the Action class in the configuration file. Follow the steps below to complete this feature:

1 Really realize the subclass of org.apache.struts.Action.exceptionHandler, override the Execute method, handle an exception in this method and return an ActionForward object 2 Configure an exception handling object in the configuration file, you can configure a global handling class or separate Configure processing for each Action

The table below defines a global handling class CustomizedExceptionHandler, which is used to process all exceptions.

Handler = "com.Yourcorp.customizedExceptionHandler"

Key = "global.error.message"

Path = "/ error.jsp"

Scope = "request"

TYPE = "java.lang.exception" />

Chapter 8: Other Web Framework Struts PrinciPle and Practice Web FrameWorksstruts is a web framework. So what is Framework? Framework concept is not very new, with the development of software development, in multi-storey software development projects, reusable, easy to expand, and have a well-tested software components, more and more people Favused. This means that people can use sufficient time to analyze, build business logic applications, rather than complicated code projects. So people will abstract the solution to the same type of problem, extract into an application framework. This is what we said. Framework's system provides a set of clear mechanisms to make developers easily extend and control the structure of the entire Framework development. Typically, there is a "command and control" component in the framework, there are many B / S WebFramework, which is also a very successful work. A section below Struts is mainly focused on the Controller process, based on the JSP and Taglib implementation VIEW. Cocoon: Jakarta's framework for processing XML, using XML as view and better combines the framework adopted by the XSLT Webwork: Jive Forum, using the Command mode for forwarding, and can combine multiple View model Turbine: same Jakarta produced . It is a servlet-based Framework that enables Java developers to build their own web applications quickly and secure. Velocity is used as the performance layer. (Velocity) TapeStry: A excellent FRAMWORK, similar to WinForm in DOTNET, use HTML and a servlet to generate a View Spring: Spring is an Application Framework serving all levels: provided Bean Configure the foundation, AOP support, JDBC extraction framework, abstract transaction support, and so on. It has a very significant feature: at a level if you don't need Spring support, you can use the string Class, only the features of some part of it. JSF: JavaServerFaces, it is not a Framework, but JSF also provides a different way of virtually generation. It can be integrated with a variety of Framework. In J2EE 1.4, the JSP2.0 specification contains JSF standards. Framework has many kinds, and Struts is not our only choice. We can choose different frameworks depending on the specific item. The reason why Struts is now more popular, and the main reason is that it is more early, the version is more stable, and is the standard implementation of MVC and Core J2EE Patterns. The future trend of development, most likely JSF Struts Spring Hibernate / JDO development model Copyright, welcome to reprint 9CBS starter, reproduced please specify the author: ice clouds

转载请注明原文地址:https://www.9cbs.com/read-4957.html

New Post(0)