- 开发环境
Myeclipse2017 / Tomcat8.5 / Struts2.5.12
- jar包导入
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
<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>
<?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>
package action;
public class action1 {
public String execute() {
System.out.println("action1");
return "success";
}
}
- 对应的jsp页面(只是简单显示而已)命名要和struts.xml中的result中的值对应,通过浏览器访问。