面试-框架-struts2

来源:互联网 发布:深圳方维网络 编辑:程序博客网 时间:2024/06/05 10:44

1、struts2的工作流程
客户端发起一个请求到servlet容器
该请求经过一系列过滤器
接着FilterDispatcher被调用,FilterDispatcher询问ActionMapper该请求是否需要调用某个action
如果经询问ActionMapper得知需要调用某个Action,则把请求交给ActionProxy
ActionProxy通过询问Configration Manager询问框架的配置文件找到需要调用的Action类
ActionProxy创建一个ActionInvocation实例
ActionInvocation调用action,并且在其前后调用相关的过滤器
一个Action执行完毕,ActionInvocation根据Xml文件里的配置返回结果,可能是页面也可能是Action

2、struts2的结果类型
dispatcher、redirect、redirectAction、steam等

3、struts2的action是单例还是多例?
多例.每一个session new一个action实例

4、 在struts2中如何实现转发和重定向?

在struts.xml中配置type=”redirect”(重定向)
type=”redirectAction”(转发)

5、Action接口提供了5个常量?
success、input、error、login、none

6、如何自定义拦截器
继承MethodFilterInterceptor,重写doIntercept方法,或者继承AbstractInterceptor,重写intercept方法。
在xml中自定义拦截器,注入拦截器栈,并且引入到Action中。
在action中使用param参数,name为excludeMethods,不拦截某些方法,
includeMethods,拦截某些方法

原创粉丝点击