第一步:获取struts
第二步:新建动态web项目
第三步:导入必要包
如下:
![](http://static.oschina.net/uploads/img/201410/18101744_MTQX.jpg)
第三步:配置web.xml
<?xml version= "1.0" encoding ="UTF-8"?>
<web-app id= "WebApp_9" 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">
<welcome-file-list >
<welcome-file> index.jsp</welcome-file >
<welcome-file> index.html</welcome-file >
</welcome-file-list >
<filter >
<filter-name> struts2</ filter-name>
<filter-class>
org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
</filter-class>
</filter >
<filter-mapping >
<filter-name> struts2</ filter-name>
<url-pattern> /*</ url-pattern>
</filter-mapping >
<!-- ... -->
</web-app>
第四步:创建struts.xml(src下面)并配置
<?xml version= "1.0" encoding ="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration2.3//EN"
"http://struts.apache.org/dtds/struts-2.3.dtd">
<struts>
<!-- 声明包 -->
<constant name="struts.enable.DynamicMethodInvocation" value="true" />
<package name="myPackage" extends= "struts-default" namespace="/" >
<!-- 定义action -->
<action name="first" >
<!-- 定义处理成功后的返回界面 -->
<result> first.jsp</result >
</action >
</package >
</struts>
第五步:测试。在index.jsp中加入一个连接,调用action
<body>
< a href ="first.action">通过struts框架 </a>
</body>
创建first.jsp
<body>
<h1> 这是通过struts框架过来的 </h1>
</body>