需求:本人要删除某一数据,需要骓是否登录,如果没有登录就转到登录页面。因为针对的是整个系统的某些方法,所以觉得用拦截器比较理想。当在拦截器里判断用户没有登录时,把异常转到action里处理,该怎么做?
以下是我写的拦截器,请高手帮忙。public class MyInterceptor extends MethodFilterInterceptor {   @Override
protected String doIntercept(ActionInvocation invocation) throws Exception {


Object username = ActionContext.getContext().getSession().get(
"username");

System.out.println("username = " + username);

if(username==null){
throw new UserSessionException();
}

String result = invocation.invoke(); return result;
}}

解决方案 »

  1.   

    ...你直接把你写的拦截器 ,配置struts的拦截器 不就OK了吗?
      

  2.   

    将异常抛给action是不现实的,而且这么做没有道理。
    当username是null的时候,给出一个全局跳转,跳到某个action去,这样不好吗?难道你还想分发到每个action中做不同的处理?
      

  3.   

    怎么跳啊,你写出来看,这可不是在Action里跳
      

  4.   

    将异常抛给action是不现实的,而且这么做没有道理。
    当username是null的时候,给出一个全局跳转,跳到某个action去,这样不好吗?难道你还想分发到每个action中做不同的处理?
      

  5.   

    什么叫这么可不是在action里跳?
    public String intercept(ActionInvocation invocation) throws Exception {
        Object username = ActionContext.getContext().getSession().get("username");
        if(username==null){
            return "LOGIN";
        }
        String result = invocation.invoke();
        return result;
    }xml里面<global-results>
        <result name="LOGIN" type="redirect">GetGeneralInfoAction</result>
    </global-results>不就完了吗?
    你到底要问什么?
      

  6.   

    至于最后你要往action跳还是往页面跳,那你自己控制一下就可以了
      

  7.   

    这样的方法可不可以??try{
    //你的拦截器
    }catch(Exception e){
    return "error";
    }然后在你的actioin中定义<result name = "error">这样不就可以了么.如果你想吧错误的信息也带出来
    那就利用struts的现实页面编码标签 现实所有内容 不过那看到也没什么用啊 捕获才是正道啊