Struts+Velocity整合示例(含源码)
1、新建Web程序
2、添加以下Jar包到lib下(11个)
commons-collections-3.1.jarcommons-digester-2.0.jarcommons-fileupload-1.2.2.jarcommons-lang-2.5.jarfreemarker-2.3.16.jarognl-3.0.1.jaroro-2.0.8.jarstruts2-core-2.2.3.1.jarvelocity-1.7.jarvelocity-tools-1.4.jarxwork-core-2.1.6.jar
<?xml version="1.0" encoding="UTF-8"?><web-appversion="2.5"xmlns="http://java.sun.com/xml/ns/javaee"xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"xsi:schemaLocation="http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd"><welcome-file-list><welcome-file>index.jsp</welcome-file></welcome-file-list><filter><filter-name>struts2</filter-name><filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class></filter><filter-mapping><filter-name>struts2</filter-name><url-pattern>*.action</url-pattern></filter-mapping></web-app>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"><struts><!-- Configuration for the default package. --><packagename="default"extends="struts-default"namespace="/"><!-- to welPage --><actionname="test"name="code">package com.ape.action;import com.opensymphony.xwork2.ActionSupport;public class TestAction extends ActionSupport {/** * */private static final long serialVersionUID = 9061932498262928875L;private String name;public String getName() {return name;}public void setName(String name) {this.name = name;}public String execute() {name = "Happy";return SUCCESS;}}
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />${name},我啊king!