引入拦截器最好的好处就是,实现了对action通过操作的可插拔管理,这样的可插拔管理基于struts.xml文件来配置实现。
下面看看,到底怎么来配置拦截器的呢。
<interceptors>
<!-- 基本拦截器的配置--!>
<interceptor name = "alias" class = "com.opensymphony.xwork2.interceptor.AliasInterceptor" />
<interceptor name = "autowiring" class = "com.opensymphony.xwork2.spring.interceptor.ActionAutowiringInterceptor" />
</interceptor>
</interceptors>
在struts中,内置的拦截器其实已经能够完成大部分的拦截任务,为了学习,下面我们看下自定义的拦截器要怎么使用:要自定义拦截器类,必须直接或间接实现Interceptor接口:
public interface Interceptor extends Serializable {
void destroy();
void init();
String intercept(ActionInvocation invocation) throws Exception;
}
public class LoginInterceptor extends AbstractInterceptor{
private static final long serialVersionUID = -5325530121178579784L;
public String intercept(ActionInvocation ai) throws Exception {
Map session = ai.getInvocationContext().getSession();
String username = (String)session.get("user");
if(username != null && username.length() > 0){
return ai.invoke();
}else{
ActionContext ac = ai.getInvocationContext();
ac.put("abc", "未登录");
return Action.INPUT;
}
}
}
只要再像上面配置文件一样配置下action, 那么就可以使用登录拦截器了。
分享到:
相关推荐
Spring in Action CN.001<br>Spring in Action CN.002<br>Spring in Action CN.003<br>Spring in Action CN.004<br>Spring in Action CN.005<br>Spring in Action CN.006<br>Spring in Action ... <br>本书信息:...
Spring in Action CN.001<br>Spring in Action CN.002<br>Spring in Action CN.003<br>Spring in Action CN.004<br>Spring in Action CN.005<br>Spring in Action CN.006<br>Spring in Action ... <br>本书信息:...
form name="myform" id="myform" action="ssss" method="post" onsubmit="getUrl();"> javascript方法: [removed] function getUrl(){ $('form').attr('action','new_url'); } [removed] 或者用单纯的...
1:非重用型:只能在被存储它的TEST中...右键ACTION PROPERTIES>EXTERNAL ACTION>USE A LOCAL,EDITABLE COPY。 调用重用型的ACTION可以在以后新版本中控件发生变化时只升级被调用的可重复型ACTION所在的源程序即可。
ACTION
Akka in Action shows you how to build message-oriented systems with Akka. This comprehensive, hands-on tutorial introduces each concept with a working example. You’ll start with the big picture of ...
jQuery in Action, Third Edition, is a fast-paced guide to jQuery, focused on the tasks you'll face in nearly any web dev project. In it, you'll learn how to traverse the DOM, handle events, perform ...
资源中示例了一个struts2的配置文件中配置的action的result结果为另外一个action的配置,该跳转的过程中是带所有参赛调整的,在另外一个action中可以接受到当前action的所有参数,此配置文件是我日常开发中的经验...
jsp自动调用action采用中间jsp方法 就是采用从欢迎页跳到action处理再转到展示页面,就可以访问页面时加载数据
Hadoop In Action 中文第二版 卷二 rar
MongoDB in Action, 2nd Edition
Spring Security in Action
spring in action所需jar包
电子书 Entity Framework 4 In Action
主要介绍了JavaScript获取网页表单action属性的方法,涉及javascript操作表单属性的技巧,具有一定参考借鉴价值,需要的朋友可以参考下
Camel in action 一书的PDF电子书 和源代码
Action-RPG Starter Kit 6.55 商店几百买的最新
Spring in action Spring in action Spring in action Spring in action Spring in action Spring in action
action之间的跳转action之间的跳转
PHP.in.Action~~~~~~~~~```