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

📄 servlet1.java

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

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

        }
    }

//网站配置
    public void admin_web(HttpServletRequest request,
                          HttpServletResponse response) throws
            ServletException, IOException, SQLException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();

        String a = toString(request.getParameter("BsCompanyName"));
        String b = toString(request.getParameter("Bbq"));
        String c = toString(request.getParameter("BsAddress"));
        String d = toString(request.getParameter("Bsqq"));
        String e = toString(request.getParameter("BsLinkman"));
        String f = toString(request.getParameter("BsEnLinkman"));
        String g = toString(request.getParameter("BsPhone"));
        String h = toString(request.getParameter("BsFax"));
        String i = toString(request.getParameter("BsWeb"));
        String j = toString(request.getParameter("BsEmail"));
        String k = toString(request.getParameter("BsWebMail"));
        String l = toString(request.getParameter("BsZipcode"));
        String m = toString(request.getParameter("BsSkins_Default"));
        try {
            String condition = "update webDes set BsCompanyName='" + a + "'," +
                               " Bbq='" + b + "'," +
                               " BsAddress='" + c + "'," +
                               " BSqq='" + d + "'," +
                               " BsLinkman='" + e + "'," +
                               " BsEnLinkman='" + f + "'," +
                               " BsPhone='" + g + "'," +
                               " BsFax='" + h + "'," +
                               " BsWeb='" + i + "'," +
                               " BsEmail='" + j + "'," +
                               " BsWebMail='" + k + "'," +
                               " BsZipcode='" + l + "'," +
                               " BsSkins_Default='" + m + "'";

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

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

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

        }
    }




//添加新闻
    public void addnew(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException, SQLException {
        String newimg = toString(request.getParameter("img"));
        String bt1 = toString(request.getParameter("bt1"));
        String lb1 = toString(request.getParameter("lb1"));
        String time1 = toString(request.getParameter("time1"));
        String nr1 = new String(request.getParameter("content1").getBytes(
                "iso8859_1"));
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        try {
            String condition =
                    " insert into addnew(nr1,bt1,time1,newimg,lb1)VALUES" +
                    "('" + nr1 + "','" + bt1 + "','" + time1 + "','" + newimg +"','"+lb1+
                     "')";
            System.out.print(condition);
            jdbc.execUpdate(condition);

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

        } catch (Exception ex) {
            ex.printStackTrace();
            out.print("<script>alert('    输入不能为空!')</script>");
            out.print("<script>history.back(-1)</script>"); //返回原来页面

        }
    }

//删除新闻
    public void delnew(HttpServletRequest request, HttpServletResponse response) throws
            ServletException, IOException {
        String[] sc = request.getParameterValues("sc");
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        try {
            if (sc != null) {
                for (int i = 0; i < sc.length; i++) {
                    String condition = "delete from addnew where id=" +
                                       sc[i];
                    request.setCharacterEncoding("gb2312");
                    String lb = request.getParameter("lb");

                    try {
          int rowcount = jdbc.execQueryName("select * from addnew where id=" + sc[i]);
         ArrayList al = jdbc.getRS();
           for(int t=0;t<rowcount;t++){
               HashMap colValue = (HashMap)al.get(t);
                            String name = (String)colValue.get("newimg");
                            String img = name.substring(18);
                            String filepath = getServletContext().getRealPath(
                                    "") + "/ShangChuangImg/" + img;
                            File file1 = new File(filepath); //删除文件
                            try {
                                file1.delete();
                            } catch (Exception e) {}

                            System.out.print(filepath);

                        }
                    } catch (Exception ex) {
                        ex.printStackTrace();
                    }
                    jdbc.execUpdate(condition);
                }

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

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

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

    }

    //添加合作伙伴
    public void addFriend(HttpServletRequest request,
                          HttpServletResponse response) throws
            ServletException, IOException, SQLException {
        String Friendimg = toString(request.getParameter("img"));
        String name = toString(request.getParameter("name"));
        String note = toString(request.getParameter("note"));
        String link = toString(request.getParameter("link"));
        String fs = toString(request.getParameter("fs"));
        String dl = toString(request.getParameter("dl"));
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        try {
            String condition =
                    " INSERT INTO friend (www_name,www_note,Friendimg,fs,dl,www_link) VALUES " +
                    "(" + "'" + name + "','" + note + "','" + Friendimg + "','" +
                    fs + "','" + dl + "','" +
                    link + "')";

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

            out.println("<script languaga=\"JavaScript\">alert(\"  添加成功!\");window.location = \"basic/admin/friend.jsp\";</script>");
            out.close();
        } catch (Exception ex) {
            ex.printStackTrace();
            out.print("<script>alert('    添加失败!')</script>");
            out.print("<script>history.back(-1)</script>"); //返回原来页面

        }
    }

    //更改合作伙伴
    public void editFriend(HttpServletRequest request,
                           HttpServletResponse response) throws
            ServletException, IOException, SQLException {
        String w = toString(request.getParameter("w"));
        String name = toString(request.getParameter("name"));
        String fs = toString(request.getParameter("fs"));
        String note = toString(request.getParameter("note"));
        String link = toString(request.getParameter("link"));
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        try {
            String condition = "update friend set www_name='" + name +
                               "'," +
                                " fs='" + fs + "'," +
                               " www_note='" + note + "'," +
                               " www_link='" + link +
                               "' where id=" + w;

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

            out.println("<script languaga=\"JavaScript\">alert(\"  修改成功!\");window.location = \"basic/admin/friend.jsp\";</script>");
            out.close();
        } catch (Exception ex) {
            ex.printStackTrace();
            out.print("<script>alert('    修改失败!')</script>");
            out.print("<script>history.back(-1)</script>"); //返回原来页面

        }
    }

//删除合作伙伴
    public void delFriend(HttpServletRequest request,
                          HttpServletResponse response) throws
            ServletException, IOException {
        response.setContentType(CONTENT_TYPE);
        PrintWriter out = response.getWriter();
        String id = toString(request.getParameter("IDdel"));
        try {
    int rowcount = jdbc.execQueryName("select * from friend where id=" + id);
    ArrayList al = jdbc.getRS();
    for(int i=0;i<rowcount;i++){
     HashMap colValue = (HashMap)al.get(i);
               String img = (String)colValue.get("Friendimg");
               String www_img = img.substring(18);
                String filepath = getServletContext().getRealPath(
                        "") + "/ShangChuangImg/" + www_img;
                File file1 = new File(filepath); //删除文件
                try {
                    file1.delete();
                } catch (Exception e) {
                    e.printStackTrace();
                }
            }

            String condition = "delete from friend where id=" +
                               id;
            jdbc.execUpdate(condition);
            out.println("<script languaga=\"JavaScript\">alert(\"    删除成功!\");window.location = \"basic/admin/friend.jsp\";</script>");

        }

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

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

    //Clean up resources
    public void destroy() {
    }
}

⌨️ 快捷键说明

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