struts.xml 配置
1. <?xml version= "1.0" encoding= "UTF-8"
2. <!DOCTYPE struts PUBLIC   
3. "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
4. "http://struts.apache.org/dtds/struts-2.0.dtd">   
5.   
6. <struts>   
7.   
8. "struts.enable.DynamicMethodInvocation" value= "false"
9. "struts.devMode" value= "false"
10. package name= "default"  extends= "struts-default">   
11. "test"  class= "com.test.TestAction">   
12. <result name= "success"  type= "freemarker"
13.         </action>   
14. "login">   
15. <result type= "freemarker"</result>
16.         </action>   
17. package>   
18. </struts> 
 *.ftl 编写
  
1. <#assign s=JspTaglibs[ "/WEB-INF/struts-tags.tld"] />   
2. <html>   
3. <head>   
4.     <title>Hello</title>   
5. </head>   
6. <body>   
7. < @s.form action= "/test.action">   
8. < @s.textfield name= "name"/>   
9. < @s.submit/>   
10. </ @s.form>   
11. </body>   
12. </html>  
  
<#assign s=JspTaglibs[ "/WEB-INF/struts-tags.tld"
这一句是为了让Freemarker识别struts2的标签,因为在Freemarker文件内,除了它自己的,都会原样显示。
 
 
web.xml 配置1. <?xml version= "1.0"  encoding= "UTF-8"
2. <web-app id= "WebApp_9"  version= "2.4"  xmlns= "http://java.sun.com/xml/ns/j2ee"
3. "http://www.w3.org/2001/XMLSchema-instance"
4. "http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">   
5.   
6.     <display-name>Struts Blank</display-name>   
7.   
8.     <filter>   
9.         <filter-name>struts2</filter-name>   
10. class>   
11. class>   
12.     </filter>   
13.   
14.     <filter-mapping>   
15.         <filter-name>struts2</filter-name>   
16.         <url-pattern>/*</url-pattern>   
17.     </filter-mapping>   
18. <servlet>   
19.         <servlet-name>JspSupportServlet</servlet-name>   
20. class >org.apache.struts2.views.JspSupportServlet</servlet- class >   
21. 1
22.     </servlet>   
23.     <welcome-file-list>   
24.         <welcome-file>login.action</welcome-file>   
25.     </welcome-file-list>   
26.   
27. </web-app>  
  
  
 java 代码编写
 1.   import com.opensymphony.xwork2.ActionSupport; 
 2.   public class TestAction extends ActionSupport { 
 3.        private String name = "ChainHou"; 
 4.        public String getName() { 
 5.              return name; 
 6.        } 
 7.        public void setName(String name) { 
 8.              this.name = name; 
 9.        } 
 10.      @Override 
 11.      public String execute() throws Exception { 
 12.             return SUCCESS; 
 13.      } 
 14.  }