Struts2+Mybatis+Freemarker+Tiles架构灵活的开发框架(三)
接着上面继续,这次我们来配置freemarker
第一,修改web.xml
<?xml version="1.0" encoding="UTF-8"?><web-app xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xmlns="http://java.sun.com/xml/ns/javaee" xmlns:web="http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd"id="WebApp_ID" version="3.0"><!-- FreeMarker配置 --><servlet><servlet-name>freemarker</servlet-name><servlet-class>freemarker.ext.servlet.FreemarkerServlet</servlet-class><init-param><param-name>TemplatePath</param-name><param-value>/</param-value></init-param><init-param><param-name>default_encoding</param-name><param-value>UTF-8</param-value></init-param></servlet><servlet><servlet-name>JspSupportServlet</servlet-name><servlet-class>org.apache.struts2.views.JspSupportServlet</servlet-class><load-on-startup>1</load-on-startup></servlet><servlet-mapping><servlet-name>freemarker</servlet-name><url-pattern>*.html</url-pattern></servlet-mapping><!-- Tiles配置 --><context-param><param-name>org.apache.tiles.impl.BasicTilesContainer.DEFINITIONS_CONFIG</param-name><param-value>/WEB-INF/tiles.xml</param-value></context-param><listener><listener-class>org.apache.struts2.tiles.StrutsTilesListener</listener-class></listener><!-- Struts2配置 --><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>/*</url-pattern></filter-mapping></web-app>
第二,修改index.action
package com.XXX.lib.action;import com.opensymphony.xwork2.ActionSupport;public class IndexAction extends ActionSupport{private static final long serialVersionUID = 1L;private String myTest;public String index(){myTest = "freeMarker";return SUCCESS;}public String getMyTest() {return myTest;}public void setMyTest(String myTest) {this.myTest = myTest;}}第三,修改test.html
tiles!${myTest?if_exists}访问http://localhost:8080/XXX/index.action出现tiles! freeMarker,ok
特别说明:不明白请在下面跟帖,有错误的地方麻烦指正