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

📄 admin.java

📁 jsp开发常用信息管理系统适合初学者学习 新闻管理
💻 JAVA
字号:
package ch06;

import java.sql.ResultSet;
import java.sql.SQLException;
import java.util.Hashtable;
import java.util.Vector;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;

public class admin
{

    public admin()
        throws Exception
    {
        handle = new handle();
        dbConn = new dbConn();
        md5 = new md5();
    }

    public void addAccount(HttpServletRequest httpservletrequest, String s)
        throws Exception
    {
        String s2 = handle.getString(httpservletrequest, "account");
        s2 = handle.GBK2ISO(s2);
        String s3 = handle.getString(httpservletrequest, "pwd");
        s3 = md5.getMD5ofStr(s3);
        int i = handle.getInt(httpservletrequest, "level");
        String s4 = ch06.handle.getDateTime();
        String s1 = "INSERT INTO " + s + "(account,pwd,level,date_time) VALUES(?,?,?,?)";
        dbConn.getPreparedStatement(s1);
        dbConn.setString(1, s2);
        dbConn.setString(2, s3);
        dbConn.setInt(3, i);
        dbConn.setString(4, s4);
        dbConn.ExeUpdate();
        dbConn.CloseConn();
    }

    public void changeLevel(HttpServletRequest httpservletrequest, String s)
        throws Exception
    {
        int i = handle.getInt(httpservletrequest, "id");
        int j = handle.getInt(httpservletrequest, "level");
        if(j == 1)
            j = 0;
        else
            j = 1;
        String s1 = "UPDATE " + s + " SET level=? WHERE id=?";
        dbConn.getPreparedStatement(s1);
        dbConn.setInt(1, j);
        dbConn.setInt(2, i);
        dbConn.ExeUpdate();
        dbConn.CloseConn();
    }

    public boolean checkLogin(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s)
        throws Exception
    {
        String s1 = handle.GBK2ISO(handle.getString(httpservletrequest, "inAccount"));
        String s2 = handle.GBK2ISO(handle.getString(httpservletrequest, "inPwd"));
        s2 = md5.getMD5ofStr(s2);
        HttpSession httpsession = httpservletrequest.getSession(true);
        boolean flag = false;
        try
        {
            String s3 = "SELECT * FROM " + s + " WHERE account=? AND pwd=?";
            dbConn.getPreparedStatement(s3);
            dbConn.setString(1, s1);
            dbConn.setString(2, s2);
            ResultSet resultset = dbConn.ExeQuery();
            if(resultset.next())
            {
                adminBean adminbean = new adminBean();
                adminbean.setId(resultset.getInt("id"));
                adminbean.setAccount(resultset.getString("account"));
                adminbean.setLevel(resultset.getInt("level"));
                httpsession.setAttribute("loginAccount", adminbean);
                flag = true;
            }
            dbConn.CloseConn();
        }
        catch(SQLException sqlexception)
        {
            System.err.println("checkLogin():" + sqlexception.getMessage());
        }
        return flag;
    }

    public void checkSupperAdmin(HttpServletRequest httpservletrequest, HttpServletResponse httpservletresponse, String s, String s1, String s2)
        throws Exception
    {
        HttpSession httpsession = httpservletrequest.getSession(true);
        String s4 = "";
        boolean flag = false;
        try
        {
            String s3 = "SELECT * FROM " + s + " WHERE page=?";
            dbConn.getPreparedStatement(s3);
            dbConn.setString(1, s1);
            ResultSet resultset = dbConn.ExeQuery();
            if(resultset.next())
                s4 = resultset.getString("visitor");
            dbConn.CloseConn();
        }
        catch(SQLException sqlexception)
        {
            System.err.println("getAdminBeanVector():" + sqlexception.getMessage());
        }
        adminBean adminbean = (adminBean)httpsession.getAttribute("loginAccount");
        String s5 = String.valueOf(adminbean.getLevel());
        if(s4.indexOf(s5) != -1)
            flag = true;
        if(!flag)
            httpservletresponse.sendRedirect(s2);
    }

    public void delAccount(HttpServletRequest httpservletrequest, String s)
        throws Exception
    {
        int i = handle.getInt(httpservletrequest, "id");
        String s1 = "DELETE FROM " + s + " WHERE id=?";
        dbConn.getPreparedStatement(s1);
        dbConn.setInt(1, i);
        dbConn.ExeUpdate();
        dbConn.CloseConn();
    }

    public Vector getAdminBeanVector(String s)
        throws Exception
    {
        Vector vector = new Vector();
        try
        {
            String s1 = "SELECT * FROM " + s + " ORDER BY id DESC";
            dbConn.getPreparedStatement(s1);
            adminBean adminbean;
            for(ResultSet resultset = dbConn.ExeQuery(); resultset.next(); vector.addElement(adminbean))
            {
                adminbean = new adminBean();
                adminbean.setId(resultset.getInt("id"));
                adminbean.setAccount(resultset.getString("account"));
                adminbean.setLevel(resultset.getInt("level"));
                adminbean.setDateTime(resultset.getString("date_time"));
            }

            dbConn.CloseConn();
        }
        catch(SQLException sqlexception)
        {
            System.err.println("getAdminBeanVector():" + sqlexception.getMessage());
        }
        return vector;
    }

    public Hashtable getPermissionInfoHashtable(HttpServletRequest httpservletrequest, String s)
        throws Exception
    {
        Hashtable hashtable = new Hashtable();
        String s2 = handle.getString(httpservletrequest, "level");
        try
        {
            String s1 = "SELECT * FROM " + s + "\tWHERE title!='' ORDER BY id DESC";
            dbConn.getPreparedStatement(s1);
            for(ResultSet resultset = dbConn.ExeQuery(); resultset.next();)
                if(resultset.getString("visitor").indexOf(s2) != -1)
                    hashtable.put(resultset.getString("title"), "checked");
                else
                    hashtable.put(resultset.getString("title"), "");

            dbConn.CloseConn();
        }
        catch(SQLException sqlexception)
        {
            System.err.println("getPermissionInfoHashtable():" + sqlexception.getMessage());
        }
        return hashtable;
    }

    public Hashtable getTypeInfoHashtable(HttpServletRequest httpservletrequest, String s, String s1)
        throws Exception
    {
        Hashtable hashtable = new Hashtable();
        Hashtable hashtable1 = new Hashtable();
        Vector vector = new Vector();
        Vector vector1 = new Vector();
        String s3 = "";
        int i = handle.getInt(httpservletrequest, "aid");
        try
        {
            String s2 = "SELECT * FROM " + s + " WHERE admin_id=?";
            dbConn.getPreparedStatement(s2);
            dbConn.setInt(1, i);
            for(ResultSet resultset = dbConn.ExeQuery(); resultset.next();)
                s3 = s3 + resultset.getString("type_id") + ",";

            s2 = "SELECT * FROM " + s1;
            dbConn.getPreparedStatement(s2);
            for(ResultSet resultset1 = dbConn.ExeQuery(); resultset1.next();)
            {
                vector1.addElement(resultset1.getString("id"));
                vector.addElement(resultset1.getString("title"));
                if(s3.indexOf(resultset1.getString("id")) != -1)
                    hashtable1.put(resultset1.getString("title"), "checked");
                else
                    hashtable1.put(resultset1.getString("title"), "");
            }

            hashtable.put("typeId", vector1);
            hashtable.put("typeTitle", vector);
            hashtable.put("typeInfoHashtable", hashtable1);
            dbConn.CloseConn();
        }
        catch(SQLException sqlexception)
        {
            System.err.println("getPermissionInfoHashtable():" + sqlexception.getMessage());
        }
        return hashtable;
    }

    public void gotoLogin(HttpServletResponse httpservletresponse, HttpSession httpsession, String s)
        throws Exception
    {
        if(httpsession.getAttribute("loginAccount") == null)
            httpservletresponse.sendRedirect(s);
    }

    public boolean modifyPwd(HttpServletRequest httpservletrequest, String s)
        throws Exception
    {
        String s3 = handle.getString(httpservletrequest, "newPwd");
        String s4 = handle.getString(httpservletrequest, "oldPwd");
        HttpSession httpsession = httpservletrequest.getSession(true);
        adminBean adminbean = (adminBean)httpsession.getAttribute("loginAccount");
        String s5 = adminbean.getAccount();
        boolean flag = false;
        s3 = md5.getMD5ofStr(s3);
        s4 = md5.getMD5ofStr(s4);
        s5 = handle.GBK2ISO(s5);
        try
        {
            String s1 = "SELECT * FROM " + s + " WHERE account=? AND pwd=?";
            dbConn.getPreparedStatement(s1);
            dbConn.setString(1, s5);
            dbConn.setString(2, s4);
            ResultSet resultset = dbConn.ExeQuery();
            if(resultset.next())
            {
                String s2 = "UPDATE " + s + " SET pwd=? WHERE account=?";
                dbConn.getPreparedStatement(s2);
                dbConn.setString(1, s3);
                dbConn.setString(2, s5);
                dbConn.ExeUpdate();
                flag = true;
            }
            dbConn.CloseConn();
        }
        catch(SQLException sqlexception)
        {
            System.err.println("modifyPwd():" + sqlexception.getMessage());
        }
        return flag;
    }

    public void modifySystemPermission(HttpServletRequest httpservletrequest, String s)
        throws Exception
    {
        String s6 = handle.getString(httpservletrequest, "level");
        String s7 = s6 + ",";
        String s8 = "," + s6;
        Hashtable hashtable = new Hashtable();
        try
        {
            String s1 = "SELECT * FROM " + s + "\tWHERE title!=''";
            dbConn.getPreparedStatement(s1);
            for(ResultSet resultset = dbConn.ExeQuery(); resultset.next(); dbConn.ExeUpdate())
            {
                int i = resultset.getInt("id");
                String s4 = resultset.getString("visitor");
                s4 = handle.Replace(s7, "", s4);
                s4 = handle.Replace(s8, "", s4);
                hashtable.put(resultset.getString("title"), s4);
                String s2 = "UPDATE " + s + " SET visitor=? WHERE id=?";
                dbConn.getPreparedStatement(s2);
                dbConn.setString(1, s4);
                dbConn.setInt(2, i);
            }

            String as[] = httpservletrequest.getParameterValues("systemItem");
            for(int j = 0; as != null && j < as.length; j++)
            {
                String s5 = (String)hashtable.get(as[j]);
                s5 = s5 + s8;
                String s9 = handle.GBK2ISO(as[j]);
                String s3 = "UPDATE " + s + " SET visitor=? WHERE title=?";
                dbConn.getPreparedStatement(s3);
                dbConn.setString(1, s5);
                dbConn.setString(2, s9);
                dbConn.ExeUpdate();
            }

            dbConn.CloseConn();
        }
        catch(SQLException sqlexception)
        {
            System.err.println("modifySystemPermission():" + sqlexception.getMessage());
        }
    }

    public void modifyTypePermission(HttpServletRequest httpservletrequest, String s)
        throws Exception
    {
        java.util.Enumeration enumeration = httpservletrequest.getParameterNames();
        int i = handle.getInt(httpservletrequest, "aid");
        try
        {
            String s1 = "DELETE FROM " + s + " WHERE admin_id=?";
            dbConn.getPreparedStatement(s1);
            dbConn.setInt(1, i);
            dbConn.ExeUpdate();
            String as[] = httpservletrequest.getParameterValues("type_id");
            for(int j = 0; as != null && j < as.length; j++)
            {
                int k = Integer.parseInt(as[j]);
                String s2 = "INSERT INTO " + s + "(admin_id,type_id) VALUES(?,?)";
                dbConn.getPreparedStatement(s2);
                dbConn.setInt(1, i);
                dbConn.setInt(2, k);
                dbConn.ExeUpdate();
            }

            dbConn.CloseConn();
        }
        catch(SQLException sqlexception)
        {
            System.err.println("modifyTypePermission():" + sqlexception.getMessage());
        }
    }

    handle handle;
    dbConn dbConn;
    md5 md5;
}

⌨️ 快捷键说明

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