1.项目右键点击MyEclipes--->Add Struts Capabilities..--->选择2.1---选中第一个Core包.
2.点击finish后生成Struts.xml文件以及web.xml的核心过滤器.
<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>*.action</url-pattern>
</filter-mapping>
3.编写Action类
public class WelcomeAction {
public String execute(){ //必须方法,且方法名为execute,返回值为String
return "success";
}
}
4.在struts.xml文件中进行相关配置
<struts>
<package name="test" extends="struts-default" namespace="/">//name值不能重复,namespace决定Action的访问路径
<action name="hello" class="com.pp.struts2.action.WelcomeAction">//类名以及标记
<result name="success" >/welcome.jsp</result> //success对应以上类的返回值,/welcome.jsp为跳转的页面
</action>
</package>
</struts>
4.jsp页面中跳转到Action
<a href="<%=path%>/hello.action">跳转欢迎界面</a> //hello.action跟以上配置有关