- 開(kāi)發(fā)環(huán)境
Myeclipse2017 / Tomcat8.5 / Struts2.5.12 - jar包導(dǎo)入
1. commons-fileupload-1.3.3.jar
2. commons-io-2.4.jar
3. commons-lang3-3.3.6.jar
4. commons-logging-1.1.3.jar
5. freemarker-2.3.23.jar
6. javassist-3.20.0-GA.jar
7. log4j-api-2.5.jar
8. log4j-core-2.8.2.jar
9. ognl-3.1.12.jar
10. struts2-core-2.5.2.jar
- 在web.xml中編寫(xiě)配置文件
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
- 寫(xiě)struts2.xml文件
<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC
"-//Apache Software Foundation//DTD Struts Configuration 2.5//EN"
"http://struts.apache.org/dtds/struts-2.5.dtd">
<struts>
<package name="action" extends="struts-default">
<!--
@package package is a unit to group action which is similar to the package in Java
package can be extended and overridden.
@attribute name it is required for distinction.
extends inherits other package
namespace URL of the web project
abstract an empty package
-->
<action name="hello" class="action.action1" >
<!--
@action action is a action that you can visit the JSP page by the action name
@attribute name it is require for distinction
flush Default is true.flush the write at the end of the action or not.
ignoreContextParams when the action is invoked ,the parameter is included.
var Push the value into Value Stack
-->
<result name="success">/hello.jsp</result>
<!--
@result Result is the definition of action
@attribute name it has default name "dispatcher".It corresponds to the function
of the JavaBean.
-->
</action>
</package>
</struts>
- 寫(xiě)java類實(shí)現(xiàn)execute()方法
package action;
public class action1 {
public String execute() {
System.out.println("action1");
return "success";
}
}
- 對(duì)應(yīng)的jsp頁(yè)面(只是簡(jiǎn)單顯示而已)命名要和struts.xml中的result中的值對(duì)應(yīng),通過(guò)瀏覽器訪問(wèn)。