第一天学习struts2
第一天学习struts2,看了6个视频讲的是struts2的入门跳转,记录一下,今天学到的知识(学习资源来自黑马程序员视频)
步骤
1、首先导入struts2的依赖包
2、创建一个jsp主页面,并输入href跳转路径
<a href="${ pageContext.request.contextPath"}/hello.action>
3、创建一个action类,其中方法为public,并且没有参数
public String execute(){
System.out.println("执行了HelloAction....");
return "success";
}
4、在struts.xml中配置Struts2的包
<!-- 配置Struts2的包 -->
<package name="hello" extends="struts-default" namespace="/">
<action name="hello" class="com.stu.action.HelloAction">
<!--跳转页面 -->
<result name="success">/demo1/success.isp</result>
</action>
</package>
5、在web.xml中配置拦截器
<filter>
<filter-name>hello</filter-name>
<filter-class>org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hello</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
6、创建一个跳转成功的success.jsp页面
运行结果展示:
如有雷同或错误,欢迎联系作者,共同探讨,共同学习!