The component tag in struts can be used to call the FTL template file of freemarker. The parameter passing using the component tag can be written as follows:
Using the property method:
<s:component template="gridComponent.ftl" templateDir="/WEB-INF/template"> <s:param name="grid" value="userss"></s:param> </s:component>
Use the get/set attribute method of the request:
<s:component template="gridComponent.ftl" templateDir="/WEB-INF/template"> <s:param name="grid" value="#request.users"></s:param> </s:component>
The following describes how to use FTL read parameters:
<#assign s=JspTaglibs["/struts-tags"] /><#assign req = parameters.grid /><#list req as item> ${item["userName"]}</#list>
Common struts action:
Package COM. obs. actions. admin; import Java. util. list; import Org. apache. struts2.servletactioncontext; import Org. springframework. stereotype. controller; import COM. obs. actions. baseadminactionsupport; import COM. obs. actions. bean. user; import COM. obs. util. common; @ controller @ suppresswarnings ("serial")/* @ namespace ("/admin") @ results ({@ result (name = "success ", location = "/WEB-INF/View/admin/user. JSP ")}) */public class useraction extends baseadminactionsupport {private list <user> userss; public list <user> getuserss () {return userss ;} public void setuserss (list <user> userss) {This. userss = userss;}/*** by default, the page executes action */@ override Public String execute () throws exception {// obtain the list of all users <COM. obs. service. bean. user> userlist = super. userservice. findusers (); // copy bean list <user> Users = Common. copyproperties (userlist, user. class); userss = users; // set the action bean to the page servletactioncontext. getrequest (). setattribute ("users", users); Return success ;}}
Userss is property, and users is the attribute of request.
[Freemarker]-call freemarker's FTL template method using struts component