Struts + FreeMarker pair super combination (1)

xiaoxiao2021-03-06  44

Struts makes you no longer care about how Servlet is placed, and FreeMarker makes you easy to make the arrangement on the page, and the parameters between the two are not issued. It is simply a natural match. The associated struts comes with the TLD tags of HTML, Logic, NESTED, Bean, Tiles, Template, and features can meet most of the cases. However, these labels are very inconvenient and flexible, and will add a lot of unnecessary content to simple HTM code. Most importantly, the syntax provided by HTML.TLD tags is very large and commonly used in hypertext syntax habits, allowing developers to waste time. FreeMarker provides features that Struts's label library can provide, and compared to other templates, there is a powerful "program" feature. If you don't have Struts, FreeMarker can also be a good combination with other frameworks because it is to do the decoupling of the front page and the background program. On the combination of the Struts project, you can use almost no need to modify the original ACTION or ActionForm code, you can directly use the FreeMarker Template FTL file to enter. You don't need to import new packages in the original action. This is also discovered after I have grown through a piece of twist road. Just configure FreeMarker in Web.xml, copy the corresponding FreeMarker.jar file to the project lib. Modify Struts-config.xml, change the original , then you will jump to the corresponding FTL template when the Action is corresponding for forward. So how is the data passed between ACTION and FTL? Very simple, Action is also used with Request.SetaTRibute ("Member", OBJ), but does not need to use GetAttribute in the FTL, but directly with FreeMarker's variable $ {member}, Easy. If this OBJ is a list property, you can read it in <#List Member AS User> $ {User.Name} in the FTL. It is also convenient to use Logic: iteerate. If you don't turn on the required HTML, Bean, or other tags you need, FreeMarker can also be completely used in the JSP page. Although I don't recommend continuing to use the Struts label. The method is as follows: <# assign html = jsptaglibs ["/ Web-inf / struts-html.tld"]> <# assign bean = jsptaglibs ["/ web-inf / struts-bean.tld"]> <# assign logic = JSptaglibs ["/ Web-INF / STRUTS-LOGIC.TLD"]>

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

New Post(0)