Struts2 開發環境搭建
一、 獲取 struts2 包。http://struts.apache.org/2.x/下載。其中的包如下
Struts2-core-2.0.9.jar
Commons-logging-1.0.4.jar
Struts2-api-2.0.0.jar
Struts2-extras-2.0.0.jar
Xword-2.0-SNAPSHOT.jar
二、 將 jar 包添加到項目中。新建 web 項目后,將 struts2 的 jar 添加到項目的 WEB-
INFO 下 lib 中。
三、 修改 web.xml。引入 FilterDispatcher 類。如下
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.4" xmlns="http://java.sun.com/xml/ns/j2ee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee
http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd">
<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>/*</url-pattern>
</filter-mapping>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
四、 在src目錄下新建一個文件,命名為struts.xml。具體可見json項目下的struts.xml
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
"http://struts.apache.org/dtds/struts-2.0.dtd">
<struts>
</struts>