如何解决如何拦截Struts 2 Action之间的导航?
| 我正在使用Struts2。当用户导航时执行其他操作是否可以识别并拦截? 我需要确定用户是否要执行与当前操作不同的操作。解决方法
这简单。只需使用Struts 2拦截器即可。
public class TestInterceptor extends AbstractInterceptor {
public String intercept(ActionInvocation invocation) throws Exception {
// Do checking here,get user from session or from parameter is OK.
// Example:
// string returned below will be redirected to result of Struts 2 action
String roleName = user.getRole().getName();
if (\"admin\".equals(roleName) {
return \"admin\";
} else if(\"user\".equals(roleName)) {
return \"user\";
}
// This means if roleName is not admin or user,the action will be invoked
return invocation.invoke();
}
}
然后只需在struts.xml配置中添加以上拦截器即可。我想这就是你想要的,对吗?我总是使用这个拦截器。
有关示例,请参见http://struts.apache.org/2.x/docs/interceptors.html或http://www.benmccann.com/blog/struts-2-tutorial-interceptors/。
版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。