⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 controllerfilter.java

📁 用java实现的一个论坛,可以供大家参考
💻 JAVA
字号:
/*******************************************************************\
*                                                                   *
*			   LightningBoard			    *
*                                                                   *
*          http://sourceforge.net/projects/lightningboard/          *
*			                                            *
*	            Copyright (c) 2002 Xiaobo Liu	            *
*                                                                   *
*********************************************************************
*                        LICENSE INFORMATION                        *
*                                                                   *
*  LightningBoard is free software; you can redistribute it and/or  *
*  modify it under the terms of the GNU General Public License as   *
*  published by the Free Software Foundation; either version 2 of   *
*  the License, or any later version.                               *
*                                                                   *
*  We don't charge anything for the use of LightningBoard, we only  *
*  require you to keep the copyright present on your site and in    *
*  the source files.                                                *
*                                                                   *
*  LightningBoard is distributed in the hope that it will be useful,*
*  but without any warranty; without even the implied warranty of   *
*  merchantability or fitness for a particular purpose. See the GNU *
*  General Public License for more details.                         *
*                                                                   *
\*******************************************************************/


package liuxiaobo.lb;

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import liuxiaobo.lb.action.*;

public class ControllerFilter implements Filter {
  protected FilterConfig filterConfig;
  public void init(FilterConfig config) {
    this.filterConfig = config;
  }
  public void destroy() {
    this.filterConfig = null;
  }
  public void doFilter(ServletRequest srequest, ServletResponse sresponse, FilterChain filterChain)
      throws IOException, ServletException{
    HttpServletRequest request = (HttpServletRequest)srequest;
    HttpServletResponse response = (HttpServletResponse)sresponse;
    String path = (String) request.getRequestURI();
    String actionString = path.substring(path.lastIndexOf("/") + 1,path.lastIndexOf("."));

    String forwardPage=null;
    try {
      if(actionString.equals("home"))
        forwardPage=new HomeAction().excute(request,response);
      else if(actionString.equals("forum"))
        forwardPage=new ForumAction().excute(request,response);
      else if(actionString.equals("topic"))
        forwardPage=new TopicAction().excute(request,response);
      else if(actionString.equals("user"))
        forwardPage=new UserAction().excute(request,response);
      else if(actionString.equals("userEdit"))
        forwardPage=new UserEditAction().excute(request,response);
      else if(actionString.equals("login"))
        forwardPage=new LoginAction().excute(request,response);
      else if(actionString.equals("register"))
        forwardPage=new RegisterAction().excute(request,response);
      else if(actionString.equals("post"))
        forwardPage=new PostAction().excute(request,response);
      else if(actionString.equals("logout"))
        forwardPage=new LogoutAction().excute(request,response);
    }catch (ActionException ex) {
      System.out.println(ex);
    }
    // forward page
    if (forwardPage!=null)
      filterConfig.getServletContext().getRequestDispatcher(forwardPage).forward(request,response);
  }
}

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -