actionInvocation.invoke()是什么意思
2012-12-07 09:58
393 查看
Struts2的自定义的验证截器
package ch06.struts2.Interceptor;
import java.util.Map;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class AuthenticationInterceptor implements Interceptor {
private static final long serialVersionUID = 1L;
public static final String USER_SESSION_KEY = "UserSessionKey";
public void destroy() {}
public void init() {}
public String intercept(ActionInvocation actionInvocation) throws Exception {
//取得Session
Map session = actionInvocation.getInvocationContext().getSession();
//从Session里获得登录时保存进session的User类
String user = (String) session.get(USER_SESSION_KEY);
//判断用户名是否为空
boolean isAuthenticated = (null!=user);
if (!isAuthenticated) {//如果未通过登录验证
//下面的那个return怎么能返回登录页面
return Action.LOGIN; //返回登录页面
}else{
// 下面的这个actionInvocation.invoke()是什么意思
return actionInvocation.invoke();//返回验证通过
}
}
}
struts.xml配置自定义的拦截器
<!-- 自定义验证拦截器 -->
<interceptors>
<interceptor name="Authentication" class="ch06.struts2.Interceptor.AuthenticationInterceptor" />
</interceptors>
<action name="Welcome">
<interceptor-ref name ="Authentication"/>
<result name="success">welcome.jsp</result>
</action>
最佳答案
actionInvocation.invoke() 就是通知struts2接着干下面的事情
比如 调用下一个拦截器 或 执行下一个Action
就等于退出了你自己编写的这个interceptor了
package ch06.struts2.Interceptor;
import java.util.Map;
import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.Interceptor;
public class AuthenticationInterceptor implements Interceptor {
private static final long serialVersionUID = 1L;
public static final String USER_SESSION_KEY = "UserSessionKey";
public void destroy() {}
public void init() {}
public String intercept(ActionInvocation actionInvocation) throws Exception {
//取得Session
Map session = actionInvocation.getInvocationContext().getSession();
//从Session里获得登录时保存进session的User类
String user = (String) session.get(USER_SESSION_KEY);
//判断用户名是否为空
boolean isAuthenticated = (null!=user);
if (!isAuthenticated) {//如果未通过登录验证
//下面的那个return怎么能返回登录页面
return Action.LOGIN; //返回登录页面
}else{
// 下面的这个actionInvocation.invoke()是什么意思
return actionInvocation.invoke();//返回验证通过
}
}
}
struts.xml配置自定义的拦截器
<!-- 自定义验证拦截器 -->
<interceptors>
<interceptor name="Authentication" class="ch06.struts2.Interceptor.AuthenticationInterceptor" />
</interceptors>
<action name="Welcome">
<interceptor-ref name ="Authentication"/>
<result name="success">welcome.jsp</result>
</action>
最佳答案
actionInvocation.invoke() 就是通知struts2接着干下面的事情
比如 调用下一个拦截器 或 执行下一个Action
就等于退出了你自己编写的这个interceptor了
相关文章推荐
- actionInvocation.invoke()是什么意思,配置自己的验证拦截器
- actionInvocation.invoke()是什么意思
- actionInvocation.invoke()是什么意思
- actionInvocation.invoke()是什么意思
- 代码清单17:调用截拦器,DefaultActionInvocation.invoke()方法的部分代码
- actionInvocation有什么用
- actionInvocation.invoke()的作用
- 登录拦截器actionInvocation.invoke()是什么意思,配置自己的验证拦截器
- actionInvocation是什么
- Struts2之ServletActionContext、ActionContext、ActionInvocation
- ActionInvocation
- Calender类中的DAY_OF_WEEK_IN_MONTH是什么意思?
- struts2 拦截器和actioninvocation
- 代码清单20:DefaultActionInvocation.createAction()方法
- MSDN中API参数说明前的[in]和[out]是什么意思
- display:inline-block是什么意思
- linux中 you have newmail in /var/spool/mail/root是什么意思
- ActionContext 、Interceptor和ActionInvocation
- Struts2源码阅读(六)_ActionProxy&ActionInvocation
- struts2 拦截器和actioninvocation、PreResultListener