jfinal拦截器301跳转

在jfinal的handle中加入

HandlerKit.redirect301("http://10.10.3.144:8080/bbb.rar", request, response, arg3);

有一些自己的业务逻辑,可以忽略

package com.dsideal.CommonIntercptor;



import java.util.concurrent.TimeoutException;



import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;



import net.rubyeye.xmemcached.exception.MemcachedException;



import com.dsideal.Util.SigarTest;

import com.jfinal.handler.Handler;

import com.jfinal.kit.HandlerKit;

import com.jfinal.plugin.memcached.MemcachedKit;

import com.jfinal.plugin.memcached.MemcachedPlugin;

import com.jfinal.render.RenderFactory;



public class ResourceHandler extends Handler{





    /**

     * 拦截器,放开报表

     */

    @Override

    public void handle(String target, HttpServletRequest request,

            HttpServletResponse response, boolean[] arg3) {

        



//        MemcachedPlugin memcachedPlugin = new MemcachedPlugin("10.10.3.151:11211");

//         memcachedPlugin.start();

        int index = target.indexOf("ReportServer");

        if (index == -1){

//            if (request.getRequestURI().indexOf(".") != -1) {

//                if (request.getRequestURI().substring(request.getRequestURI().lastIndexOf('.')).toLowerCase().equals(".zip")) {

                    try {

                        if(new Long((Long)MemcachedKit.get("dfTxBytesMb")).intValue() > 2) {

                            System.out.println("TxBytes(每秒发送的总字节数) = " + MemcachedKit.get("dfTxBytesMb") + "MB");

                            SigarTest.printA();

                            HandlerKit.redirect301("http://10.10.3.36:8817/aaa.rar", request, response, arg3);

                        } else {

                            System.out.println("TxBytes(每秒发送的总字节数) = " + MemcachedKit.get("dfTxBytesMb") + "MB");

                            SigarTest.printB();

                            HandlerKit.redirect301("http://10.10.3.144:8080/bbb.rar", request, response, arg3);

                        }

                    } catch (TimeoutException e) {

                        // TODO Auto-generated catch block

                        e.printStackTrace();

                    } catch (InterruptedException e) {

                        // TODO Auto-generated catch block

                        e.printStackTrace();

                    } catch (MemcachedException e) {

                        // TODO Auto-generated catch block

                        e.printStackTrace();

                    }

                    

//                }

//            }

                    

            nextHandler.handle(target, request, response, arg3);

            



        }

    }

}

 

你可能感兴趣的:(jFinal)