一、搭建struts2
1、导包
2、书写Action类
public class DemoAction extends ActionSupport{
public String hello1() throws Exception {
System.out.println("hello ~~");
return "success";
}
}
3、书写src/struts.xml
<struts>
<package name="hello" extends="struts-default" namespace="/">
<action name="hello" class="crm.web.action.DemoAction" method="hello1">
<result name="success">/index.jsp</result>
</action>
</package>
<package name="hello" extends="struts-default" namespace="/">
<action name="hello_*" class="crm.web.action.DemoAction" method="{1}"><!-- 取出第一个星号通配符的内容 -->
<result name="success">/index.jsp</result>
<result name="error">/error.jsp</result>
</action>
</package>
<!-- 国际化 -->
<constant name="struts.i18n.encoding" value="UTF-8"></constant>
<!-- 以什么结尾 -->
<constant name="struts.action.extension" value="action,,"></constant>
<!-- 开发模式运行 -->
<constant name="struts.devMode" value="false"></constant>
<include file="crm/web/action/struts.xml"></include>
</struts>
4、将struts2核心过滤器配置到web.xml
<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>
完成