当前位置:   article > 正文

java filter 跳转页面_java Filter编写和跳转实现

java filter后跳转到指定页面

package com.bizviva.binding;

import java.io.IOException;

import javax.servlet.Filter;

import javax.servlet.FilterChain;

import javax.servlet.FilterConfig;

import javax.servlet.ServletException;

import javax.servlet.ServletRequest;

import javax.servlet.ServletResponse;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

import com.bizviva.bizcrm.ClientPlatform;

public class BindFilter implements Filter {

public static final String onlinereg =

"/binding/onlinereg/reg.do";

public static final String onlinereginclude =

"/binding/onlinereg/displaySellerRegister.do";

public static final String binding =

"/binding/onlinereg/binding.do";

public static final String SubBind =

"/binding/onlinereg/SubBind.do";

public static final String login =

"/common/member/login.do";

public static final String waiting =

"/binding/remote/waitReg.do";

static int MEMBER_STATUS_NO = 1;

static int MEMBER_STATUS_YES = 0;

public void destroy() {

}

public void doFilter(ServletRequest request,

ServletResponse response,

FilterChain

chain) throws IOException, ServletException {

HttpServletRequest req =

(HttpServletRequest) request;

HttpServletResponse res =

(HttpServletResponse) response;

String path =

req.getContextPath();

String file

=req.getServletPath();

if

(file.endsWith("/index.html") || file.endsWith(".do")){

}else{

chain.doFilter(request,

response);

return;

}

String site = req.getScheme() +

"://" + req.getServerName() + ":"

+

req.getServerPort() + path;

System.out.println("site===>>>"+site

+ " file " + file);

int MEMBER_ID = 0;

int MEMBER_STATUS = -1; // 0未开通

1开通 -1未申请 -2申请没通过

String uri =

req.getRequestURI();

System.out.println("request

uri:" + uri);

// 检测本地是否 有这个标识

try {

MEMBER_ID =

ClientPlatform.getConfig().getInt("client.memberId");

} catch (Exception e) {

MEMBER_ID =

-1;

}

try {

MEMBER_STATUS

= ClientPlatform.getConfig().getInt(

"client.memberStatus");

} catch (Exception e) {

MEMBER_STATUS

= -1;

}

if (MEMBER_ID <=

0) { // 未申请注册

if

(uri.endsWith(login) | uri.endsWith(waiting)) { // 如果进入登录页面

跳转

String

tmpPath = req.getContextPath();

tmpPath

= tmpPath.concat(binding);

//site

+= binding;

System.out.println("tmpPath==>>"

+tmpPath);

res.sendRedirect(tmpPath);

} else

{

chain.doFilter(request,

response);

}

} else if (MEMBER_ID

> 0) { // 已申请注册

if

(MEMBER_STATUS == MEMBER_STATUS_YES) { // 绑定成功

chain.doFilter(request,

response);

} else { //

注册 等待审批

//

远程注册了, 并且 还没开通

if

(!uri.endsWith(waiting)) {

System.out.println("query

audit status...."+req.getServerName());

String

tmpPath = req.getContextPath();

tmpPath

= tmpPath.concat(waiting);

System.out.println("waiting

Path==>>" +tmpPath);

res.sendRedirect(tmpPath); return;

}

else {

chain.doFilter(request,

response);

}

}

}

}

public void init(FilterConfig config) throws

ServletException {

}

public static int getMEMBER_STATUS_NO()

{

return MEMBER_STATUS_NO;

}

public int getMEMBER_STATUS_YES() {

return MEMBER_STATUS_YES;

}

public void setMEMBER_STATUS_YES(int

member_status_yes) {

MEMBER_STATUS_YES =

member_status_yes;

}

}

声明:本文内容由网友自发贡献,不代表【wpsshop博客】立场,版权归原作者所有,本站不承担相应法律责任。如您发现有侵权的内容,请联系我们。转载请注明出处:https://www.wpsshop.cn/w/思考机器/article/detail/61363
推荐阅读
相关标签
  

闽ICP备14008679号