Struts开发步骤:
1.导入strutsjar包到lib
2.在web.xml里面配置
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="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">
<display-name></display-name>
<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>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
</web-app>
3.写action
//要继承com.opensymphony.xwork2.ActionSupport
public class MyAction extends ActionSupport{
@Override
public String execute() throws Exception {//重写execute
System.out.println("221111");
System.out.println("8845454");
return "success";//这个返回值是对应struts.xml配置的name
}
}
4.配置action 注意路径 src/struts.xml,要带文件头, <package name="xxxx" extends="struts-default">,package 名可以随便写,但是extends="struts-default"是固定的
<?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>
<package name="xxxx" extends="struts-default">
<action name="hello" class="my.struts.MyAction" method="execute">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>