1、index.jsp
<body>
<a href = "${pageContext.request.contextPath }/user/hello.action">
访问第一个Struts2案例
</a>
</body>
2、Struts.xml
<struts>
<package name="user" namespace="/user" extends="struts-default">
<action name="hello" class="com.sd.action.HelloAction" method="execute">
<result name="success">/success.jsp</result>
</action>
</package>
</struts>
3、编写动作类:一般以Action结尾。它就是一个POJO
public class HelloAction {
public String execute(){
System.out.println("动作方法execute执行了");
return "success";
}
}
4、编写结果页面:视图(success.jsp)
<body>
Congratulation!!!
</body>
5、解决struts.xml编写没有提示的问题
在eclipse中,选Window–>Preferences–>XML Catalog–>Add–>Location选择FileSystem或Workspace,找到struts-2.3.dtd –> Key type:URI–>key:http://struts.apache.org/dtds/struts-2.3.dtd –> OK