首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > 网站开发 > Web前端 >

Struts+Velocity调整示例(含源码)

2012-09-13 
Struts+Velocity整合示例(含源码)1、新建Web程序2、添加以下Jar包到lib下(11个)commons-collections-3.1.jar

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




3、修改web.xml
<?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>



4、添加struts.xml到src下,并修改
<!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;}}


6、新建test.vm到WebRoot根目录
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />${name},我啊king!


7、运行:http://localhost:8080/velocity/test.action${name},我啊king!  zyhui98 写道为什么不直接打包呢。
这就是模板啊。

热点排行