如清晰度低,可转PC网页观看高清版本:
http://v.qq.com/x/page/u0565acptbm.html
入门示例
1.hello Struts2
流程:/hello.action->StrutsPrePareAndExecuteFilter(web.xml)->HelloAction->Result(dipatcher)(sturts.xml)->hello.jsp
1:编写hello.jsp
2:编写HelloAction.java
controller:
public @ResponseBody String XXXX(String name){...}
action:
private String name;
3:配置web.xml中Struts2的启动项StrutsPrePareAndExecuteFilter
<!-- struts2的启动拦截 -->
<filter>
<filter-name>strutsMVC</filter-name>
<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>strutsMVC</filter-name>
<url-pattern>*.action</url-pattern>
</filter-mapping>
4:添加struts.xml
<!-- namespace默认是/ -->
<package name="demo" extends="struts-default" namespace="/demo">
<!--name代表的请求路径 ,class对应的就是请求处理类,method默认的就是execute -->
<action name="hello" class="com.xdl.action.HelloAction" method="execute">
<!-- result代表的就是方法返回处理结果,type:dispather, -->
<result name="success" type="dispatcher">/WEB-INF/jsp/hello.jsp</result>
</action>
</package>
请求名:
/hello.action:接口请求名:hello 请求后缀名:.action,命名空间路径/
/demo1/dddd/hello.action:接口请求名:hello,请求后缀名:.action,命名空间路径:/demo1/dddd/