团队作业(五):冲刺总结(五)

团队作业(五):冲刺总结(五)

1.今日任务安排

  • 学习自己的负责的模块的相关知识,自己上网查询或两两交流学习,主要学习数据库相关、Java后端设计、WEB前端设计如CSS样表语法、JS语法等。

  • 开会确定每个人撰写的前端和后端部分代码以及数据库部分代码

  • 开始撰写具体的代码

    2.遇到的困难

    由于有关于web前端后端的知识是上个学期学习的,因此一开始对于代码的编写非常的生疏,有很多相关的知识都已经遗忘,于是在w3school上大家进行了上时间的复习,在回忆起上学期学习的知识以后,开始撰写代码。

3.今日成果

  • 前端完成的代码:

CheckerController.java:

点击查看代码
package controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.CRUDHelper;

public class DepartmentController extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public DepartmentController() {
        super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    @Override
    public void destroy() {
        super.destroy(); // Just puts "destroy" string in log
        // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html;charset=gb2312");
        request.setCharacterEncoding("gb2312");

        CRUDHelper ib = new CRUDHelper();
        String name = request.getParameter("name");
        String sql = "insert into dep(name) values('"+name+"')";
        int responseText = ib.insertANDupdateANDdel(sql);
        if(responseText == -1 ){
            request.setAttribute("message","'添加失败,学院名或存在'");
        }else{
            request.setAttribute("message","'添加成功'");
        }

        request.getRequestDispatcher("/admin/dep.jsp").forward(request, response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    @Override
    public void init() throws ServletException {
        // Put your code here
    }

}

DeleteController:

点击查看代码
package controller;

import java.io.IOException;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.CRUDHelper;

import javax.servlet.RequestDispatcher;

public class DeleteController extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public DeleteController() {
        super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    @Override
    public void destroy() {
        super.destroy(); // Just puts "destroy" string in log
        // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html;charset=gb2312");
        request.setCharacterEncoding("gb2312");

        String sql = "";
        String str = "";
        CRUDHelper ib = new CRUDHelper();

        String admin = request.getParameter("admin");
        String dep = request.getParameter("dep");
        String document = request.getParameter("document");

        if(admin != null && !admin.equals("")){
            sql = "delete from examine where document in (select id from document where admin="+admin+")";
            ib.insertANDupdateANDdel(sql);
            sql = "delete from document where admin="+admin;
            ib.insertANDupdateANDdel(sql);
            sql = "delete from admin where id="+admin;
            ib.insertANDupdateANDdel(sql);
            str = "/admin/systemuser.jsp";            
        }
        if(dep != null && !dep.equals("")){
            sql = "delete from examine where dep in (select id from document where dep="+dep+")";
            ib.insertANDupdateANDdel(sql);
            sql = "delete from examine where dep="+dep;
            ib.insertANDupdateANDdel(sql);
            sql = "delete from document where dep="+dep;
            ib.insertANDupdateANDdel(sql);
            sql = "delete from dep where id="+dep;
            ib.insertANDupdateANDdel(sql);
            str = "/admin/dep.jsp";            
        }
        if(document != null && !document.equals("")){
            sql = "delete from examine where document="+document;
            ib.insertANDupdateANDdel(sql);
            sql = "delete from document where id="+document;
            ib.insertANDupdateANDdel(sql);
            str = "/admin/document.jsp";            
        }

        request.getRequestDispatcher(str).forward(request, response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occure
     */
    @Override
    public void init() throws ServletException {
        // Put your code here
    }

}

DepartmentController:

点击查看代码
package controller;

import java.io.IOException;
import java.io.PrintWriter;

import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

import pojo.CRUDHelper;

public class DepartmentController extends HttpServlet {

    /**
     * Constructor of the object.
     */
    public DepartmentController() {
        super();
    }

    /**
     * Destruction of the servlet. <br>
     */
    @Override
    public void destroy() {
        super.destroy(); // Just puts "destroy" string in log
        // Put your code here
    }

    /**
     * The doGet method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to get.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    @Override
    public void doGet(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {
        doPost(request, response);
    }

    /**
     * The doPost method of the servlet. <br>
     *
     * This method is called when a form has its tag value method equals to post.
     * 
     * @param request the request send by the client to the server
     * @param response the response send by the server to the client
     * @throws ServletException if an error occurred
     * @throws IOException if an error occurred
     */
    @Override
    public void doPost(HttpServletRequest request, HttpServletResponse response)
            throws ServletException, IOException {

        response.setContentType("text/html;charset=gb2312");
        request.setCharacterEncoding("gb2312");

        CRUDHelper ib = new CRUDHelper();
        String name = request.getParameter("name");
        String sql = "insert into dep(name) values('"+name+"')";
        int responseText = ib.insertANDupdateANDdel(sql);
        if(responseText == -1 ){
            request.setAttribute("message","'添加失败,学院名或存在'");
        }else{
            request.setAttribute("message","'添加成功'");
        }

        request.getRequestDispatcher("/admin/dep.jsp").forward(request, response);
    }

    /**
     * Initialization of the servlet. <br>
     *
     * @throws ServletException if an error occurs
     */
    @Override
    public void init() throws ServletException {
        // Put your code here
    }

}

Checker:

点击查看代码
package helper;

import java.io.UnsupportedEncodingException;
import java.text.SimpleDateFormat;
import java.util.Date;


public class Checker {

    /**
     * �Ƿ�Ϊ���ֺ�Ӣ����֤
     *
     */
    public int getIntAndChar(String str){
        char c;
        int i;
        for (i = 0; i<str.length(); i++){
            c = str.charAt(i);
            if(!((c>='0' && c<='9') || (c>='a' && c<='z') || (c>='A' && c<='Z'))){
                break;
            }
        }//�ж��ַ��Ƿ���ij������
        if(i < str.length()){
            return -1;
        }else{
            return 0;
        }
    }

    /**
     * �Ƿ�Ϊ������֤
     *
     */
    public int getInt(String str){
        char c;
        int i;
        for (i = 0; i<str.length(); i++){
            c = str.charAt(i);
            if(!(c>='0' && c<='9')){
                break;
            }
        }//�ж��ַ��Ƿ���ij������
        if(i < str.length()){
            return -1;
        }else{
            return 0;
        }
    }

    /**
     * �Ƿ�Ϊ�Ƿ��ַ���֤
     *
     */
    public boolean getLawlessChar(String str){
        boolean flag = false;
        char c;
        for(int i = 0;i < str.length();i++){
            c = str.charAt(i);
            switch(c){
            case '<' : flag = true; break;
            case '>' : flag = true; break;
            case '"' : flag = true; break;
            case '&' : flag = true; break;
            case ' ' : flag = true; break;
            }
        }
        return flag;
    }

    /**
     * ����HTML�ĵ�
     *
     */
    public String htmlspecialchars(String str) {
        str = str.replaceAll("&", "&");
        str = str.replaceAll("<", "<");
        str = str.replaceAll(">", ">");
        str = str.replaceAll("\"", """);
        return str;
    }

    /**
     * ����ת��
     * ��gb2312����ת����unicode����
     */
    public String getUnicode(String str) {
        if(str != null){
            try {
                return new String(str.getBytes("iso8859_1"),"gb2312");
            } catch (UnsupportedEncodingException e) {
                // TODO �Զ����� catch ��
                e.printStackTrace();
                return str;
            }
        }else{
            return null;
        }
    }

    /**
     * ����ת��
     * ��unicode����ת����gb2312����
     */
    public String getGb2312(String str) {
        if(str != null){
            try {
                return new String(str.getBytes("gb2312"),"iso8859_1");
            } catch (UnsupportedEncodingException e) {
                // TODO �Զ����� catch ��
                e.printStackTrace();
                return str;
            }
        }else{
            return null;
        }
    }

    /**
     * ��ʽ������ ��-��-�� Сʱ��0-23��:����:��
     */
    public String getSystemDate(){
        SimpleDateFormat df = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date date = new Date();
        return df.format(date);
    }

    /**
     * ��������
     * precision ���ȣ������Ǵ���0������������С�����λ(���磺1λ��1��2λ��2���Դ�����)
     */
    public float getRround(float f,int precision){
        int n = 1;
        for(int i = 1;i <= precision;i++){
            n *= 10;
        }
        int tem = (int)(f*n+0.5);
        float ff = ((float)tem/n);
        return ff;
    }
}

SQLConnection:

点击查看代码
package helper;

import java.sql.*;
public class SQLConnection {
    static String dbDriver="com.mysql.jdbc.Driver";        
    static{
        try{
            //Class.forName(dbDriver).newInstance(); 
//            Class.forName("com.mysql.jdbc.Driver"); 
  //          Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
        }catch(Exception ex){
            System.out.print("---------------------om.microsoft.sqlserver.jdbc.SQLServerDri");
            ex.printStackTrace();
        }

    }

    public static Connection getConn(){
        try{
            Class.forName(dbDriver).newInstance(); 
            Connection conn=DriverManager.getConnection("jdbc:mysql://127.0.0.1/gwlzxt?user=root&password=123456&useUnicode=true&characterEncoding=GBK");
//            Connection conn = DriverManager.getConnection("jdbc:mysql://localhost/northwind","root","123");
 //           Connection conn=DriverManager.getConnection("jdbc:odbc:twtweb");
            return conn;
        }catch(Exception ex){
            ex.printStackTrace();
            return null;
        }
    }
    public static void close(Connection conn,Statement st,ResultSet rs){
        if(rs!=null){
            try{
                rs.close();
            }catch(SQLException ex){
            }
       }
       if(st!=null){
           try {
               st.close();
           }catch(Exception ex){
           }
       }
       if(conn!=null){
           try{
               conn.close();
           }catch(Exception ex){
           }
       }
    }

}

4.燃尽图

5.小组合照

陈子昂 徐嘉远 林梓祺 陈鑫 陈俊池 杨赛
4h 4h 3.5h 3.5h 3.5h 4h
posted @ 2022-12-06 21:53  六个核桃、、  阅读(42)  评论(0编辑  收藏  举报