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

📄 checklogontag.java

📁 jsp做的一个在线考试,不错的哈.可以看看,这个我测试通过了的.
💻 JAVA
字号:
package org.mmxbb.exam.business;

import java.io.IOException;
import javax.servlet.http.HttpSession;
import javax.servlet.jsp.JspException;
import javax.servlet.jsp.JspWriter;
import javax.servlet.jsp.tagext.TagSupport;

import org.mmxbb.exam.dao.ExamineeDAO;

public class CheckLogonTag
    extends TagSupport {

  private LogonBean logonBean = new LogonBean();
  private String logon = "logon";
  private String page = "/index.jsp";
  private String role = "";
  private String display = "false";
  private String logonInfo = "";

  public String getLogon() {
    return logon;
  }

  public void setLogon(String logon) {
    this.logon = logon;
  }

  public String getPage() {
    return page;
  }

  public void setPage(String page) {
    this.page = page;
  }

  public String getRole() {
    return role;
  }

  public void setRole(String role) {
    this.role = role;
  }

  public String getDisplay() {
    return display;
  }

  public void setDisplay(String display) {
    this.display = display;
  }

  public int doStartTag() throws JspException {
    return (SKIP_BODY);
  }

  public int doEndTag() throws JspException {
    ExamineeDAO eDAO = null;
    String examinee_id = null;
    String examinee_name = null;
    boolean valid = false;
    HttpSession session = pageContext.getSession();
    if ( (session != null) && (session.getAttribute(logon) != null)) {
      try {
        logonBean = (LogonBean) session.getAttribute(logon);
        examinee_id = logonBean.getLogon();
        eDAO = new ExamineeDAO();
        examinee_name = eDAO.findByKey(examinee_id).getName();
        this.logonInfo = examinee_id + "  考生姓名:" + examinee_name + " ";
        if (CheckRole(role, logonBean)) {
          valid = true;
        }
      } catch (Exception e) {
        valid = false;
      }
    }

    // Forward control based on the results
    if (valid) {
      return (EVAL_PAGE);
    } else {
      try {
        pageContext.forward(page);
      } catch (Exception e) {
        throw new JspException(e.toString());
      }
      return (SKIP_PAGE);
    }
  }

  public boolean CheckRole(String role, LogonBean logonBean) {
    if ( (role.equals("admin") && logonBean.isAuthority()) ||
        ( (role.equals("user")) && (logonBean.getLogon() != null) ||
         (! ("".equals(logonBean.getLogon()))))) {
      if ("true".equals(display)) {
        print(logonInfo);
      }
      return true;
    } else {
      return false;
    }
  }

  private void print(String text) {
    JspWriter writer = pageContext.getOut();
    try {
      writer.print(text);
    } catch (IOException e) {
      e.printStackTrace();
    }
  }

  /**
   * Release any acquired resources.
   */
  public void release() {
    super.release();
    this.logon = "logon";
    this.page = "/index.jsp";
  }
  public String getLogonInfo() {
    return logonInfo;
  }
  public void setLogonInfo(String logonInfo) {
    this.logonInfo = logonInfo;
  }
}

⌨️ 快捷键说明

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