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

📄 servlet1.java

📁 JAVA 开发的一个企业网站 JAVABEAN+JSP +ACCE
💻 JAVA
📖 第 1 页 / 共 2 页
字号:
package mfkvit;

import javax.servlet.*;
import javax.servlet.http.*;
import java.io.*;
import java.util.*;
import java.sql.*;
import mfkvit.JdbcBean;

public class Servlet1 extends HttpServlet {
    private static final String CONTENT_TYPE = "text/html; charset=GBK";
    JdbcBean jdbc = new JdbcBean();
    MD5_Test md5 = new MD5_Test();
    //Initialize global variables
    public void init() throws ServletException {
    }

    //字符串处理
    public String toString(String s) {
        if (s == null) s = "";
        try {
            byte b[] = s.getBytes("ISO-8859-1");
            s = new String(b);
        } catch (Exception ex) {}
        return s;
    }

    //Process the HTTP Get request
    public void doPost(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {
        String admin = toString(request.getParameter("admin"));
        if (admin.equals("addAdmin"))
            try {
                addAdmin(request, response);
            } catch (Exception ex) {}
        if (admin.equals("delAdmin"))
            try {
                delAdmin(request, response);
            } catch (Exception ex) {}
        if (admin.equals("editAdmin"))
            try {
                editAdmin(request, response);
            } catch (Exception ex) {}
        if (admin.equals("admin_lxfs"))
            try {
                admin_lxfs(request, response);
            } catch (Exception ex) {}

        if (admin.equals("addnew"))
            try {
                addnew(request, response);
            } catch (Exception ex) {}
        if (admin.equals("delnew"))
            try {
                delnew(request, response);
            } catch (Exception ex) {}

        if (admin.equals("jianjie"))
            try {
                jianjie(request, response);
            } catch (Exception ex) {}


        if (admin.equals("friend"))
            try {
                addFriend(request, response);
            } catch (Exception ex) {}
        if (admin.equals("editfriend"))
            try {
                editFriend(request, response);
            } catch (Exception ex) {}
        if (admin.equals("delfriend"))
            try {
                delFriend(request, response);
            } catch (Exception ex) {}
        if (admin.equals("admin_web"))
            try {
                admin_web(request, response);
            } catch (Exception ex) {}
            }
    //添加管理员
    public void addAdmin(HttpServletRequest request,
                         HttpServletResponse response) throws
            ServletException, IOException, SQLException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        String AdminName = toString(request.getParameter("glyzh"));
        String RealName = toString(request.getParameter("sf"));
        String PassWord = toString(request.getParameter("glymm"));
        String realPassWord = toString(request.getParameter("qrmm"));
        PassWord = md5.MD5_Test(PassWord);
        realPassWord = md5.MD5_Test(realPassWord);
        if (!PassWord.equals(realPassWord)) {
            out.print("<script>alert('两次输入密码不同!(打*的必须填写)!!')</script>");
            out.print("<script>history.back(-1)</script>"); //返回原来页面

        } else {
            try {
                String condition =
                        " INSERT INTO Madmin(AdminName,RealName,PassWord) VALUES " +
                        "(" + "'" + AdminName + "','" + RealName + "','" +
                        PassWord + "')";
                System.out.print(condition);
                jdbc.execUpdate(condition);
                out.println("<script languaga=\"JavaScript\">alert(\"添加成功!\");window.location = \"basic/admin/admin.jsp\";</script>");
            } catch (Exception ex) {
                out.print("<script>alert('    输入不能为空')</script>");
                out.print("<script>history.back(-1)</script>"); //返回原来页面
            }
        }
    }

    //删除管理员
    public void delAdmin(HttpServletRequest request,
                         HttpServletResponse response) throws
            ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        String[] sc = request.getParameterValues("sc");
        try {
            if (sc != null) {
                for (int i = 0; i < sc.length; i++) {
                    String condition = "delete from Madmin where id=" +
                                       sc[i];
                    System.out.print(condition);
                    jdbc.execUpdate(condition);
                }

                out.println("<script languaga=\"JavaScript\">alert(\"删除成功!\");window.location = \"basic/admin/admin.jsp\";</script>");

            }

        } catch (Exception ex) {
            ex.printStackTrace();
        }

        out.print("<script>alert('    请选择删除内容!!')</script>");
        out.print("<script>history.back(-1)</script>"); //返回原来页面

    }

    //*更改管理员
     public void editAdmin(HttpServletRequest request,
                           HttpServletResponse response) throws
             ServletException, IOException, SQLException {
         response.setContentType(CONTENT_TYPE);
         PrintWriter out = response.getWriter();
         String AdminName = toString(request.getParameter("glyzh"));
         String RealName = toString(request.getParameter("sf"));
         String PassWord = toString(request.getParameter("glymm"));
         PassWord = md5.MD5_Test(PassWord);
         String realPassWord = toString(request.getParameter("qrmm"));

         realPassWord = md5.MD5_Test(realPassWord);
         if (!PassWord.equals(realPassWord)) {
             out.print("<script>alert('两次输入密码不同!(打*的必须填写)!!')</script>");
             out.print("<script>history.back(-1)</script>"); //返回原来页面

         }
         // response.sendRedirect("/WebModule1/admin/addAdmin.jsp");
         else if (AdminName.equals("") || RealName.equals("") ||
                  PassWord.equals("")) {
             out.print("<script>alert('    输入不能为空')</script>");
             out.print("<script>history.back(-1)</script>"); //返回原来页面
         } else {
             String id = toString(request.getParameter("glyID"));

             try {
                 String condition = "update Madmin set AdminName='" + AdminName +
                                    "'," +
                                    " RealName='" + RealName + "'," +
                                    " PassWord='" + PassWord +
                                    "' where ID=" + id;

                 System.out.print(condition);
                 jdbc.execUpdate(condition);
                 out.println("<script languaga=\"JavaScript\">alert(\"你以成功更改信息,确定返回管理界面!\");window.location = \"basic/admin/admin.jsp\";</script>");
             } catch (Exception ex) {

                 out.print("<script>alert('请正确填写信息!(打*的必须填写)!!')</script>");
                 out.print("<script>history.back(-1)</script>");
             }

         }
     }
  //联系我们
    public void admin_lxfs(HttpServletRequest request,
                           HttpServletResponse response) throws
            ServletException, IOException, SQLException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        String GS_note = new String(request.getParameter("content1").getBytes(
                "iso8859_1"));
        String GS_name = toString(request.getParameter("GS_name"));
        String GS_web = toString(request.getParameter("GS_web"));
        String GS_address = toString(request.getParameter("GS_address"));
        String GS_zipcode = toString(request.getParameter("GS_zipcode"));
        String GS_fax = toString(request.getParameter("GS_fax"));
        String GS_phone2 = toString(request.getParameter("GS_phone2"));
        String GS_phone3 = toString(request.getParameter("GS_phone3"));
        String GS_phone4 = toString(request.getParameter("GS_phone4"));
        String GS_phone5 = toString(request.getParameter("GS_phone5"));
        String GS_qq1 = toString(request.getParameter("GS_qq1"));
        String GS_email = toString(request.getParameter("GS_email"));
        String GS_phone = toString(request.getParameter("GS_phone"));
        try {
            String condition = "update lxfs set GS_name='" + GS_name +
                               "', GS_web='" + GS_web +
                               "', GS_address='" + GS_address +
                               "', GS_zipcode='" + GS_zipcode +
                               "', GS_phone='" + GS_phone +
                               "', GS_fax='" + GS_fax +
                               "', GS_qq1='" + GS_qq1 +
                               "', GS_note='" + GS_note +
                               "', GS_email='" + GS_email + "'";
            System.out.print(condition);
            jdbc.execUpdate(condition);

            out.println("<script languaga=\"JavaScript\">alert(\"   修改成功!\");window.location = \"basic/admin/lxfs.jsp\";</script>");
            out.close();
        } catch (Exception ex) {
            ex.printStackTrace();

            out.print("<script>alert('    修改失败')</script>");
            out.print("<script>history.back(-1)</script>"); //返回原来页面

        }
    }

    //公司信息简介
    public void jianjie(HttpServletRequest request,
                        HttpServletResponse response) throws
            ServletException, IOException, SQLException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        String gsjj = new String(request.getParameter("content1").getBytes(
                "iso8859_1"));
        try {
            String condition = "update lxfs set gsjj='" + gsjj + "'";

            System.out.print(condition);
            jdbc.execUpdate(condition);

            out.println("<script languaga=\"JavaScript\">alert(\"   修改成功!\");window.location = \"basic/admin/jianjie.jsp\";</script>");
            out.close();
        } catch (Exception ex) {
            ex.printStackTrace();

⌨️ 快捷键说明

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