package com.interceptot; import com.opensymphony.xwork2.Action; import com.opensymphony.xwork2.ActionContext; import com.opensymphony.xwork2.ActionInvocation; import com.opensymphony.xwork2.interceptor.AbstractInterceptor; public class LoginInterceptor extends AbstractInterceptor { @Override public String intercept(ActionInvocation invocation) throws Exception { // 取得请求相关的ActionContext实例 String user=(String)ActionContext.getContext.getSession().get("user"); // 如果没有登陆,都返回重新登陆 if (user != null && user.equals("")) { return invocation.invoke(); } ActionContext.put("message", "你还没有登录"); return LOGIN; } }
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd"> <struts> <package name="authority" extends="struts-default"> <!-- 定义一个拦截器 --> <interceptors> <interceptor name="authority" class="com.LoginInterceptor"> </interceptor> <!-- 拦截器栈 --> <interceptor-stack name="mydefault"> <interceptor-ref name="defaultStack" /> <interceptor-ref name="authority" /> </interceptor-stack> </interceptors> <defalut-interceptor-ref name="mydefault" /> <!-- 定义全局Result --> <global-results> <!-- 当返回login视图名时,转入/login.jsp页面 --> <result name="login">/login.jsp</result> </global-results> <action name="loginform" class="com.LoginFormAction"> <result name="success">/login.jsp</result> </action> <action name="login" class="com.LoginAction"> <result name="success">/welcome.jsp</result> <result name="error">/login.jsp</result> <result name="input">/login.jsp</result> </action> <action name="show" class="com.ShowAction"> <result name="success">/show.jsp</result> <!-- 使用此拦截器 --> <interceptor-ref name="mydefault" /> </action> </package> </struts>
相关推荐
Struts2全局、局部自定义拦截器源码。
struts2自定义拦截器.pdf
Struts2自定义拦截器实现防止重复提交
strut2 配置自定义拦截器 包括struts2.xml 和 action对应的xml 以及拦截器 可能有点简单 但是基本配置都有
JSP 开发之Struts2内建自定义拦截器.docx
NULL 博文链接:https://llxhna.iteye.com/blog/1067851
由于struts2标签的性能不好,项目组决定不使用,但是如果用struts2自带的拦截器防止重复提交又必须struts标签,所以只好自定拦器实现
综合使用servlet filter与struts2 interceptor对权限进行验证。
本篇文章主要介绍了struts2自定义拦截器的示例代码,小编觉得挺不错的,现在分享给大家,也给大家做个参考。一起跟随小编过来看看吧
此实例实现功能:用户需要指定用户名登陆, 登陆成功进入相应页面执行操作,否则返回到登陆页面进行登陆, 当直接访问操作页面(登陆后才能访问的页面)时则不允许,须返回登陆页面。
主要给大家介绍了关于Struts2学习基础教程之拦截器机制与自定义拦截器的相关资料,文中通过示例代码介绍的非常详细,对大家的学习或者工作具有一定的参考学习价值,需要的朋友们下面随着小编来一起学习学习吧
Struts2_自定义拦截器 struts2_3500_my_interceptor
struts2的自定义拦截器代码
struts2 用拦截器 实现用户权限登录 可以直接运行,只单单用到struts的东西。
struts2的自定义拦截器代码例子
主要介绍了JSP 开发之Struts2内建自定义拦截器的相关资料,需要的朋友可以参考下
自定义拦截器的实现以及拦截器的详细配置,配置文件里面有特别详细的注释,希望对刚接触拦截器的同学有帮助