[color=red][size=medium]1、新建Web程序[/size][/color]
[color=red][size=medium]2、添加以下Jar包到lib下(11个)[/size][/color]
[color=red][size=medium]3、修改web.xml[/size][/color]
[color=red][size=medium]4、添加struts.xml到src下,并修改[/size][/color]
[color=red][size=medium]5、新建包:com.ape.action,新建TestAction[/size][/color]
[color=red][size=medium]6、新建test.vm到WebRoot根目录[/size][/color]
[color=red][size=medium]7、运行:[url]http://localhost:8080/velocity/test.action[/url][/size][/color]
[color=red][size=medium]2、添加以下Jar包到lib下(11个)[/size][/color]
commons-collections-3.1.jar
commons-digester-2.0.jar
commons-fileupload-1.2.2.jar
commons-lang-2.5.jar
freemarker-2.3.16.jar
ognl-3.0.1.jar
oro-2.0.8.jar
struts2-core-2.2.3.1.jar
velocity-1.7.jar
velocity-tools-1.4.jar
xwork-core-2.1.6.jar
[color=red][size=medium]3、修改web.xml[/size][/color]
<?xml version="1.0" encoding="UTF-8"?>
<web-app
version="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>
[color=red][size=medium]4、添加struts.xml到src下,并修改[/size][/color]
<!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. -->
<package
name="default"
extends="struts-default"
namespace="/">
<!-- to welPage -->
<action
name="test"
class="com.ape.action.TestAction">
<result
type="velocity">/test.vm</result>
</action>
</package>
</struts>
[color=red][size=medium]5、新建包:com.ape.action,新建TestAction[/size][/color]
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;
}
}
[color=red][size=medium]6、新建test.vm到WebRoot根目录[/size][/color]
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
${name},我啊king!
[color=red][size=medium]7、运行:[url]http://localhost:8080/velocity/test.action[/url][/size][/color]