1.struts框架准备工作
1.导入包
在这个下面的WEB-INF/lib里的全部的包
2.书写Action类
public class HelloWord { public String hello() { System.out.println("Hello World"); return "success"; } }
3.书写src/strurs.xml的配置文件
<struts> <!-- package:分类 namespace:命名空间 extend:继承 --> <package name="hello" namespace="/test" extends="struts-default" > <!-- name:访问路径名,class:处理类的全类名 method:要这此类调用的方法 --> <action name="helloWorld" class="cn.test.deno.HelloWord" method="hello"> <!-- 处理结果集,默认是转发 --> <result name="success">/hello.jsp</result> </action> </package> </struts>
4.配置struts2核心过滤器到web.xml
<!-- 配置struts核心过滤器 --> <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>
5.测试