关于java拦截器的问题

hanyue198528 2010-12-28 09:25:03
最近要做一个权限
写了拦截器,没有效果
根本没有执行
不知道哪里配置错了
那位高手指点下
struts.xml
<package name="authority" extends="struts-default">
<interceptors>
<!--定义一个名为authority的拦截器-->
<interceptor class="com.qhkj.car.comm.AccessInterceptor" name="accessInterceptor"/>
<!--定义一个包含权限检查的拦截器栈-->
<interceptor-stack name="mydefault">

<!--配置内建默认拦截器
<interceptor-ref name="defaultStack"/>-->
<!--配置自定义的拦截器-->
<interceptor-ref name="accessInterceptor"/>
</interceptor-stack>
</interceptors>
<default-interceptor-ref name="mydefault" />
<!--定义全局Result-->
<global-results>
<result name="login">login.jsp</result>
<result name="error">/error.jsp </result>
</global-results>
</package>
...全文
160 2 打赏 收藏 转发到动态 举报
写回复
用AI写文章
2 条回复
切换为时间正序
请发表友善的回复…
发表回复
hanyue198528 2010-12-28
  • 打赏
  • 举报
回复
弄好了,不过还是谢谢
昨天我在一个strut里写的一个packge有错就写了2个
今天写成一个又没错了,现在可以了
liaojianbiao 2010-12-28
  • 打赏
  • 举报
回复
strut2的拦截器的一个例子。。。


拦截器定义,,这里是一个判断超时的拦截器功能
<interceptors>
<interceptor name="Timeout" class="com.myproject.util.TimeOutInterceptor"/>
</interceptors>

action定义。。。。。。。。。。。
<action name="cf*" method="{1}" class="com.myproject.action.user.ConfigAction">
<!-- 引用自定义的拦截器 -->
<interceptor-ref name="Timeout">
<param name="excludeMethods">
Switch,UpdCss <!-- action中的这两个方法生效 -->
</param>
</interceptor-ref>
<interceptor-ref name="basicStack"/> <!-- struts 内置的默认拦截器 -->
<result name="config">/user/config.jsp</result>
</result>


//拦截器的实现。。。。。。。
package com.myproject.util;

import com.opensymphony.xwork2.ActionInvocation;
import com.opensymphony.xwork2.interceptor.MethodFilterInterceptor;
import java.util.Map;

/**
* 通用拦截器,判断用户超时
* @author maodrc
*/
public class TimeOutInterceptor extends MethodFilterInterceptor {

@Override
protected String doIntercept(ActionInvocation ai) throws Exception {
Map sessionMap = ai.getInvocationContext().getSession();

String username = (String) sessionMap.get("username");
if (com.maxneting.util.Util.isNull(username)) {
return "timeout";
} else {
return ai.invoke();
}
}
}

50,531

社区成员

发帖
与我相关
我的任务
社区描述
Java相关技术讨论
javaspring bootspring cloud 技术论坛(原bbs)
社区管理员
  • Java相关社区
  • 小虚竹
  • 谙忆
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧