zoukankan      html  css  js  c++  java
  • 12月9日 自查后续

    在上次登陆的基础上加上了公文的变化系统

    package com.hjf.dao;
    
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    import java.util.ArrayList;
    import java.util.List;
    
    import com.hjf.entity.Course;
    import com.hjf.util.DBUtil;
    
    /**
     * 课程Dao
     * Dao层操作数据
     * @author Hu
     *
     */
    public class CourseDao {
    
        /**
         * 添加
         * @param course
         * @return
         */
        public boolean add(Course course) {
            String sql = "insert into gongwen(leibie,biaoti,main) values('" + course.getLeibie() + "','" + course.getBiaoti() + "','" + course.getMain() + "')";
            //创建数据库链接
            Connection conn = DBUtil.getConn();
            Statement state = null;
            boolean f = false;
            int a = 0;
            
            try {
                state = conn.createStatement();
                state.executeUpdate(sql);
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                //关闭连接
                DBUtil.close(state, conn);
            }
            
            if (a > 0) {
                f = true;
            }
            return f;
        }
    
        /**
         * 删除
         * 
         * @param id
         * @return
         */
        public boolean delete (int id) {
            boolean f = false;
            String sql = "delete from gongwen where id='" + id + "'";
            
            Connection conn = DBUtil.getConn();
            Statement state = null;
            int a = 0;
            
            try {
                state = conn.createStatement();
                a = state.executeUpdate(sql);
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(state, conn);
            }
            
            if (a > 0) {
                f = true;
            }
            return f;
        }
    
        /**
         * 修改
         * @param name
         * @param pass
         */
        public boolean update(Course course) {
            String sql = "update gongwen set leibie='" + course.getLeibie() + "', biaoti='" + course.getBiaoti() + "', main='" + course.getMain()
                + "' where id='" + course.getId() + "'";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            boolean f = false;
            int a = 0;
    
            try {
                state = conn.createStatement();
                a = state.executeUpdate(sql);
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(state, conn);
            }
            
            if (a > 0) {
                f = true;
            }
            return f;
        }
        
        /**
         * 验证课程名称是否唯一
         * true --- 不唯一
         * @param name
         * @return
         */
        public boolean leibie(String biaoti) {
            boolean flag = false;
            String sql = "select biaoti from gongwen where biaoti = '" + biaoti + "'";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            ResultSet rs = null;
            
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                while (rs.next()) {
                    flag = true;
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(rs, state, conn);
            }
            return flag;
        }
        
        /**
         * 通过ID得到课程信息
         * @param id
         * @return
         */
        public Course getCourseById(int id) {
            String sql = "select * from gongwen where id ='" + id + "'";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            ResultSet rs = null;
            Course course = null;
            
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                while (rs.next()) {
                    String leibie = rs.getString("leibie");
                    String biaoti = rs.getString("biaoti");
                    String main = rs.getString("main");
                    
                    
                    course = new Course(id, leibie,biaoti,main);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(rs, state, conn);
            }
            
            return course;
        }
        
        /**
         * 通过name得到Course
         * @param name
         * @return
         */
        public Course getCourseByName(String biaoti) {
            String sql = "select * from gongwen where biaoti ='" + biaoti + "'";
            Connection conn = DBUtil.getConn();
            Statement state = null;
            ResultSet rs = null;
            Course course = null;
            
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                while (rs.next()) {
                    int id = rs.getInt("id");
                    
                    String leibie = rs.getString("leibie");
                    String main = rs.getString("main");
                    
                    
                    course = new Course(id,leibie,biaoti,main);
                }
            } catch (Exception e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(rs, state, conn);
            }
            
            return course;
        }
        
        /**
         * 查找
         * @param name
         * @param teacher
         * @param classroom
         * @return
         */
        public List<Course> search(String leibie, String biaoti, String main) {
            String sql = "select * from gongwen where ";
            
            if (leibie != "") {
                sql += "sex like '%" + leibie + "%'";
            }
            if (biaoti != "") {
                sql += "minzu like '%" + biaoti + "%'";
            }
            if (main != "") {
                sql += "zhuce like '%" + main + "%'";
            }
            
            List<Course> list = new ArrayList<>();
            Connection conn = DBUtil.getConn();
            Statement state = null;
            ResultSet rs = null;
    
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                Course bean = null;
                while (rs.next()) {
                    int id = rs.getInt("id");
                    String leibie2 = rs.getString("leibie");
                    String biaoti2 = rs.getString("biaoti");
                    String main2 = rs.getString("main");
                    
                    
                    bean = new Course(id, leibie2, biaoti2, main2);
                    list.add(bean);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(rs, state, conn);
            }
            
            return list;
        }
        
        /**
         * 全部数据
         * @param name
         * @param teacher
         * @param classroom
         * @return
         */
        public List<Course> list() {
            String sql = "select * from gongwen";
            List<Course> list = new ArrayList<>();
            Connection conn = DBUtil.getConn();
            Statement state = null;
            ResultSet rs = null;
    
            try {
                state = conn.createStatement();
                rs = state.executeQuery(sql);
                Course bean = null;
                while (rs.next()) {
                    int id = rs.getInt("id");
                    String leibie2 = rs.getString("leibie");
                    String biaoti2 = rs.getString("biaoti");
                    String main2 = rs.getString("main");
                    
                    
                    bean = new Course(id, leibie2, biaoti2, main2);
                    list.add(bean);
                }
            } catch (SQLException e) {
                e.printStackTrace();
            } finally {
                DBUtil.close(rs, state, conn);
            }
            
            return list;
        }
    
    }
    package com.hjf.entity;
    
    public class Course {
    
        private int id;
        private String leibie;
        private String biaoti;
        private String main;
        
        
        public int getId() {
            return id;
        }
        public void setId(int id) {
            this.id = id;
        }
        public String getLeibie() {
            return leibie;
        }
        public void setLeibie(String leibie) {
            this.leibie = leibie;
        }
        public String getBiaoti() {
            return biaoti;
        }
        public void setBiaoti(String biaoti) {
            this.biaoti = biaoti;
        }
        public String getMain() {
            return main;
        }
        public void setMain(String main) {
            this.main = main;
        }
        
        public Course() {}
        
        public Course(int id, String leibie, String biaoti, String main) {
            this.id = id;
            this.leibie = leibie;
            this.biaoti = biaoti;
            this.main = main;
            
            
        }
        
        public Course(String leibie, String biaoti, String main) {
            
            this.leibie = leibie;
            this.biaoti = biaoti;
            this.main = main;
        }
    }
    package com.hjf.service;
    
    import java.util.List;
    
    import com.hjf.dao.CourseDao;
    import com.hjf.entity.Course;
    
    /**
     * CourseService
     * 服务层
     * @author Hu
     *
     */
    public class CourseService {
    
        CourseDao cDao = new CourseDao();
        
        /**
         * 添加
         * @param course
         * @return
         */
        public boolean add(Course course) {
            boolean f = false;
            if(!cDao.leibie(course.getBiaoti())) {
                cDao.add(course);
                f = true;
            }
            return f;
        }
        
        /**
         * 删除
         */
        public void del(int id) {
            cDao.delete(id);
        }
        
        /**
         * 修改
         * @return 
         */
        public void update(Course course) {
            cDao.update(course);
        }
        
        /**
         * 通过ID得到一个Course
         * @return 
         */
        public Course getCourseById(int id) {
            return cDao.getCourseById(id);
        }
    
        /**
         * 通过Name得到一个Course
         * @return 
         */
        public Course getCourseByName(String biaoti) {
            return cDao.getCourseByName(biaoti);
        }
        
        /**
         * 查找
         * @return 
         */
        public List<Course> search(String leibie, String biaoti, String main) {
            return cDao.search( leibie,biaoti,main);
        }
        
        /**
         * 全部数据
         * @return 
         */
        public List<Course> list() {
            return cDao.list();
        }
    }
    package com.hjf.servlet;
    
    import java.io.IOException;
    import java.util.List;
    
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import com.hjf.entity.Course;
    import com.hjf.service.CourseService;
    
    @WebServlet("/CourseServlet")
    public class CourseServlet extends HttpServlet {
        
        private static final long serialVersionUID = 1L;
    
        CourseService service = new CourseService();
        
        /**
         * 方法选择
         */
        protected void service(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
            req.setCharacterEncoding("utf-8");
            String method = req.getParameter("method");
            
            if ("add".equals(method)) {
                add(req, resp);
            } else if ("del".equals(method)) {
                del(req, resp);
            } else if ("update".equals(method)) {
                update(req, resp);
            } else if ("search".equals(method)) {
                search(req, resp);
            } else if ("getcoursebyid".equals(method)) {
                getCourseById(req, resp);
            } else if ("getcoursebyname".equals(method)) {
                getCourseByName(req, resp);
            } else if ("list".equals(method)) {
                list(req, resp);
            }
        }
    
        /**
         * 添加
         * @param req
         * @param resp
         * @throws IOException 
         * @throws ServletException 
         */
        private void add(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException {
            req.setCharacterEncoding("utf-8");
            //获取数据
            String leibie = req.getParameter("leibie");
            String biaoti = req.getParameter("biaoti");
            String main = req.getParameter("main");
            
            Course course = new Course(leibie,biaoti,main);
            
            //添加后消息显示
            if(service.add(course)) {
                req.setAttribute("message", "添加成功");
                req.getRequestDispatcher("add.jsp").forward(req,resp);
            } else {
                req.setAttribute("message", "公文标题重复,请重新录入");
                req.getRequestDispatcher("add.jsp").forward(req,resp);
            }
        }
        
        /**
         * 全部
         * @param req
         * @param resp
         * @throws ServletException 
         */
        private void list(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            
            List<Course> courses = service.list();
            req.setAttribute("courses", courses);
            req.getRequestDispatcher("list.jsp").forward(req,resp);
        }
    
        /**
         * 通过ID得到Course
         * @param req
         * @param resp
         * @throws ServletException 
         */
        private void getCourseById(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            int id = Integer.parseInt(req.getParameter("id"));
            Course course = service.getCourseById(id);
            req.setAttribute("course", course);
            req.getRequestDispatcher("detail2.jsp").forward(req,resp);
        }
    
        /**
         * 通过名字查找
         * 跳转至删除
         * @param req
         * @param resp
         * @throws IOException
         * @throws ServletException 
         */
        private void getCourseByName(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            String biaoti = req.getParameter("biaoti");
            Course course = service.getCourseByName(biaoti);
            if(course == null) {
                req.setAttribute("message", "查无此公文!");
                req.getRequestDispatcher("del.jsp").forward(req,resp);
            } else {
                req.setAttribute("course", course);
                req.getRequestDispatcher("detail.jsp").forward(req,resp);
            }
        }
        
        /**
         * 删除
         * @param req
         * @param resp
         * @throws IOException
         * @throws ServletException 
         */
        private void del(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            int id = Integer.parseInt(req.getParameter("id"));
            service.del(id);
            req.setAttribute("message", "删除成功!");
            req.getRequestDispatcher("del.jsp").forward(req,resp);
        }
        
        /**
         * 修改
         * @param req
         * @param resp
         * @throws IOException
         * @throws ServletException 
         */
        private void update(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            int id = Integer.parseInt(req.getParameter("id"));
            String leibie = req.getParameter("leibie");
            String biaoti = req.getParameter("biaoti");
            String main = req.getParameter("main");
            
            Course course = new Course(id,leibie,biaoti,main);
            
            
            service.update(course);
            req.setAttribute("message", "修改成功");
            req.getRequestDispatcher("CourseServlet?method=list").forward(req,resp);
        }
        
        /**
         * 查找
         * @param req
         * @param resp
         * @throws ServletException 
         */
        private void search(HttpServletRequest req, HttpServletResponse resp) throws IOException, ServletException{
            req.setCharacterEncoding("utf-8");
            String leibie = req.getParameter("leibie");
            String biaoti = req.getParameter("biaoti");
            String main = req.getParameter("main");
            
            List<Course> courses = service.search(leibie,biaoti,main);
            req.setAttribute("courses", courses);
            req.getRequestDispatcher("searchlist.jsp").forward(req,resp);
        }
    }
    package com.hjf.util;
    
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    /**
     * 数据库连接工具
     * @author Hu
     *
     */
    public class DBUtil {
        
        public static String db_url = "jdbc:mysql://localhost:3306/user";
        public static String db_user = "root";
        public static String db_pass = "root";
        
        public static Connection getConn () {
            Connection conn = null;
            
            try {
                Class.forName("com.mysql.jdbc.Driver");//加载驱动
                conn = DriverManager.getConnection(db_url, db_user, db_pass);
            } catch (Exception e) {
                e.printStackTrace();
            }
            
            return conn;
        }
        
        /**
         * 关闭连接
         * @param state
         * @param conn
         */
        public static void close (Statement state, Connection conn) {
            if (state != null) {
                try {
                    state.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
        
        public static void close (ResultSet rs, Statement state, Connection conn) {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            if (state != null) {
                try {
                    state.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
            
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
    
        public static void main(String[] args) throws SQLException {
            Connection conn = getConn();
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            String sql ="select * from course";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            if(rs.next()){
                System.out.println("空");
            }else{
                System.out.println("不空");
            }
        }
    }
    package dao;
    
    import java.sql.Connection;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
    
    import entry.user;
    import util.DBUtil;
    
    public class userDao {
        //
        
            
            
            public static boolean id(String id,String pwd) {
                boolean f = false;
                String sql = "select * from denglu where id = '" + id + "' and password = '"+pwd+"'";
                //
                Connection conn = DBUtil.getConn();
                Statement state = null;
                ResultSet rs = null;       
                try {
                    state = conn.createStatement();
                    rs = state.executeQuery(sql);
                    if (rs.next()) {
                        f = true;
                    }
                } catch (SQLException e) {
                    e.printStackTrace();
                } finally {
                    DBUtil.close(rs, state, conn);
                }
                return f;
            }
    }
    package entry;
    
    public class user {
    private String id;
    private String password;
    
    
    
    public String getId() {
        return id;
    }
    public void setId(String id) {
        this.id = id;
    }
    public String getPassword() {
        return password;
    }
    public void setPassword(String password) {
        this.password = password;
    }
    
    public user(){}
    public user( String password) {
        
        this.password = password;
    };
    public user(String id, String password) {
        super();
        this.id = id;
        this.password = password;
        
    }
    }
    package servlet;
    
    import java.io.IOException;
    import javax.servlet.ServletException;
    import javax.servlet.annotation.WebServlet;
    import javax.servlet.http.HttpServlet;
    import javax.servlet.http.HttpServletRequest;
    import javax.servlet.http.HttpServletResponse;
    
    import dao.userDao;
    import entry.user;
    
    
    /**
     * Servlet implementation class AddServlet
     */
    @WebServlet("/AddServlet")
    public class AddServlet extends HttpServlet {
        private static final long serialVersionUID = 1L;
           
        /**
         * @see HttpServlet#HttpServlet()
         */
       
            
            
            protected void service(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
                 request.setCharacterEncoding("utf-8");
                 //
                 String id = request.getParameter("id");
                 String password = request.getParameter("password");
                 
               
                 
                
                  System.out.println(id);
                 System.out.println(password);
                 if(userDao.id(id,password)) {
                     request.setAttribute("message", "登录成功");
                     request.getRequestDispatcher("chenggong.jsp").forward(request,response);
                 } else {
                     request.setAttribute("message", "登录失败");
                     request.getRequestDispatcher("houtai.jsp").forward(request,response);
                 }
            }
            
            
            
            protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    
                doGet(request, response);
            }
    
        
    
    
        /**
         * @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
         */
        protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
            // TODO Auto-generated method stub
            response.getWriter().append("Served at: ").append(request.getContextPath());
        }
    
        /**
         * @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
         */
    
    
    }
    package util;
     
    import java.sql.Connection;
    import java.sql.DriverManager;
    import java.sql.PreparedStatement;
    import java.sql.ResultSet;
    import java.sql.SQLException;
    import java.sql.Statement;
     
    /*
     * 鏁版嵁搴撹繛鎺ュ伐鍏�
     */
    public class DBUtil {
         
        public static String db_url = "jdbc:mysql://localhost:3306/user?useSSL=false";
        public static String db_user = "root";
        public static String db_pass = "root";
         
        public static Connection getConn () {
            Connection conn = null;
             
            try {
                Class.forName("com.mysql.jdbc.Driver");//鍔犺浇椹卞姩
                conn = DriverManager.getConnection(db_url, db_user, db_pass);
            } catch (Exception e) {
                e.printStackTrace();
            }
             
            return conn;
        }
         
        /*10鍏抽棴杩炴帴*/
        public static void close (Statement state, Connection conn) {
            if (state != null) {
                try {
                    state.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
             
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
         
        public static void close (ResultSet rs, Statement state, Connection conn) {
            if (rs != null) {
                try {
                    rs.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
             
            if (state != null) {
                try {
                    state.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
             
            if (conn != null) {
                try {
                    conn.close();
                } catch (SQLException e) {
                    e.printStackTrace();
                }
            }
        }
     
        public static void main(String[] args) throws SQLException {
            Connection conn = getConn();
            PreparedStatement pstmt = null;
            ResultSet rs = null;
            String sql ="select * from user";
            pstmt = conn.prepareStatement(sql);
            rs = pstmt.executeQuery();
            if(rs.next()){
                System.out.println("123");
            }else{
                System.out.println("456");
            }
        }
    }
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    
    </head>
    <body>
        <%
             Object message = request.getAttribute("message");
             if(message!=null && !"".equals(message)){
         
        %>
             <script type="text/javascript">
                  alert("<%=request.getAttribute("message")%>");
             </script>
        <%} %>
        <div align="center">
            <h1 style="color: black;">公文信息录入</h1>
            <a href="chenggong.jsp">返回主页</a>
            <form action="CourseServlet?method=add" method="post" onsubmit="return check()">
                <div class="a">
                    公文类别<input type="text" id="leibie" name="leibie"/>
                </div>
                <div class="a">
                    公文标题<input type="text" id="biaoti" name="biaoti" />
                </div>
                <div class="a">
                    公文内容<input type="text" id="main" name="main" />
                </div>
                <div class="a">
                    <button type="submit" class="b">保&nbsp;&nbsp;&nbsp;存</button>
                </div>
            </form>
        </div>
        <script type="text/javascript">
            function check() {
                var leibie = document.getElementById("leibie");;
                var main = document.getElementById("main");
                var biaoti = document.getElementById("biaoti");
                
                
                //非空
                if(leibie.value == '') {
                    alert('公文类别为空');
                    leibie.focus();
                    return false;
                }
                if(main.value == '') {
                    alert('公文内容为空');
                    main.focus();
                    return false;
                }if(biaoti.value == '') {
                    alert('公文标题为空');
                    main.focus();
                    return false;
                }
                
                
            }
        </script>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>公文系统</title>
    
    </head>
    <body>
        <div align="center">  
            
            <div class="a">
                <a href="add.jsp">公文信息登记</a>
            </div>
            <div class="a">
                <a href="CourseServlet?method=list">公文信息修改</a>
            </div>
            <div class="a">
                <a href="del.jsp">公文信息删除</a>
            </div>
            <div class="a">
                <a href="search.jsp">公文信息查询</a>
            </div>
        </div>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    
    </head>
    <body>
        <%
             Object message = request.getAttribute("message");
             if(message!=null && !"".equals(message)){
         
        %>
             <script type="text/javascript">
                  alert("<%=request.getAttribute("message")%>");
             </script>
        <%} %>
        <div align="center">
            <h1 style="color: black;">公文信息删除</h1>
            <a href="chenggong.jsp">返回主页</a>
            <form action="CourseServlet?method=getcoursebyname" method="post" onsubmit="return check()">
                <div class="a">
                    公文标题<input type="text" id="biaoti" name="biaoti"/>
                </div>
                <div class="a">
                    <button type="submit" class="b">&nbsp;&nbsp;&nbsp;</button>
                </div>
            </form>
        </div>
        <script type="text/javascript">
            function check() {
                var biaoti = document.getElementById("biaoti");;
                
                //非空
                if(biaoti.value == '') {
                    alert('公文标题为空');
                    biaoti.focus();
                    return false;
                }
            }
        </script>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    <style>
        .a{
            margin-top: 20px;
        }
        .b{
            font-size: 20px;
            width: 160px;
            color: white;
            background-color: greenyellow;
        }
        .tb, td {
            border: 1px solid black;
            font-size: 22px;
        }
    </style>
    </head>
    <body>
        <div align="center">
            <h1 style="color: black;">公文信息删除</h1>
            <a href="chenggong.jsp">返回主页</a>
            <table class="tb">
                <tr>
                    <td>公文类别</td>
                    <td>${course.leibie}</td>
                </tr>
                <tr>
                    <td>公文标题</td>
                    <td>${course.biaoti}</td>
                </tr>
                <tr>
                    <td>公文内容</td>
                    <td>${course.main}</td>
                </tr>
                
            </table>
            <div class="a">
                <a onclick="return check()" href="CourseServlet?method=del&id=${course.id}">&nbsp;&nbsp;&nbsp;</a>
            </div>
        </div>
        <script type="text/javascript">
            function check() {
                if (confirm("真的要删除吗?")){
                    return true;
                }else{
                    return false;
                }
            }
        </script>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    
    </head>
    <body>
        <%
             Object message = request.getAttribute("message");
             if(message!=null && !"".equals(message)){
         
        %>
             <script type="text/javascript">
                  alert("<%=request.getAttribute("message")%>");
             </script>
        <%} %>
        <div align="center">
            <h1 style="color: black;">公文信息修改</h1>
            <a href="chenggong.jsp">返回主页</a>
            <form action="CourseServlet?method=update" method="post" onsubmit="return check()">
                <div class="a">
                    公文类别<input type="text" id="leibie" name="leibie" value="${course.leibie}"/>
                </div>
                <div class="a">
                    公文标题<input type="text" id="biaoti" name="biaoti" value="${course.biaoti}"/>
                </div>
                <div class="a">
                    公文内容<input type="text" id="main" name="main" value="${course.main}"/>
                </div>
                
                <input type="hidden" id="id" name="id" value="${course.id}"/>
                <div class="a">
                    <button type="submit" class="b">&nbsp;&nbsp;&nbsp;</button>
                </div>
            </form>
        </div>
        <script type="text/javascript">
            function check() {
                var leibie = document.getElementById("leibie");;
                var biaoti = document.getElementById("biaoti");
                var main = document.getElementById("main");
                
                
                //非空
                if(leibie.value == '') {
                    alert('公文类别为空');
                    leibie.focus();
                    return false;
                }
                if(main.value == '') {
                    alert('公文内容为空');
                    main.focus();
                    return false;
                }if(biaoti.value == '') {
                    alert('公文标题为空');
                    main.focus();
                    return false;
                }
            }
        </script>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=utf-8"
        pageEncoding="utf-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="utf-8">
    <title>Insert title here</title>
    </head>
    <body>
    <%
             Object message = request.getAttribute("message");
             if(message!=null && !"".equals(message)){
         
        %>
             <script type="text/javascript">
                  alert("<%=request.getAttribute("message")%>");
             </script>
        <%} %>
        <div align="center">
            <h6 style="color: black;">管理员登陆</h6>
         
            <form name = "form1" action=AddServlet method="post" onsubmit="return check_submit()">
        <table>
                <tr>
                    <td>登陆账号</td>
                    <td colspan="2"> <input type="text" id="id" name="id"  maxlength="12" onblur="blur_id()" onfocus="focus_id()"/></td>
                    <td width="300"><div id="result"></td>
                </tr>
                <tr>
                    <td>登陆密码</td>
                    <td colspan="2"> <input type="password" id="password" name="password" onblur="blur_pass()" onfocus="focus_pass()" /></td>
                    <td width="300"><div id="result1"></td>
                </tr>
                <tr><td>验证码</td>
                <td>
                
         <input type="text" value="" placeholder="请输入验证码(区分大小写)" 
         style="height:20px;position: relative; font-size:16px;"id ="text">
         <canvas id="canvas" width="110" height="30" onclick="dj()" 
          style="border: 1px solid #ccc;
            border-radius: 5px;"></canvas>
         <button type=submit
         class="btn" onclick="sublim()">提交</button>
    
                </td>
       
                </tr>
            
                
    
    
        </table>
        </form>
        </div>
        <script type="text/javascript">
    /*
        表单验证
    */
    var flag = true;   // flag 如果为true(即用户名合法)就允许表单提交, 如果为false(即用户名不合法)阻止提交
    /*function focus_pass()
    {
        var nameObj = document.getElementById("result1");
        nameObj.innerHTML = "由六位字符和数字组成";
        nameObj.style.color="#999";
        }
    function blur_pass()
    {
        var nameObj = document.getElementById("result1");
        // 判断用户名是否合法
        var str2 = check_user_pass(document.form1.password.value);
        nameObj.style.color="red";
        if ("密码合法" ==  str2)
        {
            flag = true;
            nameObj.innerHTML = str2;
        }
        else
        {
            nameObj.innerHTML = str2;
        }
    }
    
    function check_user_pass(str)
    {  var str2 = "密码合法";
    if ("" == str)
    {
        str2 = "密码为空";
        return str2;
    }
    else if (str.length!=6)
    {
        str2 = "用户名应是六位组成";
        return str2;
    }
    else if (!check_word(str))
    {
        str2 = "未含有英文字符";
        return str2;
    }
    
    return str2;
        
        
        }
    
    
    
    
    
    function focus_id()
    {
        var nameObj = document.getElementById("result");
        nameObj.innerHTML = "由六到十二英文字符和数字组成";
        nameObj.style.color="#999";
        }
    function blur_id()
    {
        var nameObj = document.getElementById("result");
        // 判断用户名是否合法
        var str2 = check_user_id(document.form1.id.value);
        nameObj.style.color="red";
        if ("用户名合法" ==  str2)
        {
            flag = true;
            nameObj.innerHTML = str2;
        }
        else
        {
            nameObj.innerHTML = str2;
        }
    }
    
    function check_user_id(str)
    {
        var str2 = "用户名合法";
        if ("" == str)
        {
            str2 = "用户名号为空";
            return str2;
        }
        else if ((str.length<=4)||(str.length>=12))
        {
            str2 = "用户名应是六到十二位组成";
            return str2;
        }
        else if (!check_word(str))
        {
            str2 = "未含有英文字符";          
            return str2;
        }
        else if(!check_firstword(str))
        {
            str2 = "必须以英文字母开头";
            return str2;
        }
        return str2;
    }
    
    
    function check_firstword(str)
    {   var arr = ["a", "b", "c", "d", "e", "f", "g", "h","i","j", "k", "l", "m", "n", "o", "p", "q","r", "s", "t", "u", "v", "w", "x", "y","z","A", "B", "C", "D", "E", "F", "G", "H","I","J", "K", "L", "M", "N", "O", "P", "Q","R","S", "T", "U", "V", "W", "X", "Y", "Z"];
    for (var i = 0; i < arr.length; i++)
    {
            if (arr[i] == str.charAt(0))
            {
                return true;
            }
    }   
    return false;
        }
    
    
    function check_word(str)
    {   var arr = ["a", "b", "c", "d", "e", "f", "g", "h","i","j", "k", "l", "m", "n", "o", "p", "q","r", "s", "t", "u", "v", "w", "x", "y","z","A", "B", "C", "D", "E", "F", "G", "H","I","J", "K", "L", "M", "N", "O", "P", "Q","R","S", "T", "U", "V", "W", "X", "Y", "Z"];
    for (var i = 0; i < arr.length; i++)
    {
        for (var j = 0; j < str.length; j++)
        {
            if (arr[i] == str.charAt(j))
            {
                return true;
            }
        }
    }   
    return false;
        }
    
    // 验证用户名是否含有特殊字符
    function check_other_char(str)
    {
        var arr = ["&", "\\", "/", "*", ">", "<", "@", "!"];
        for (var i = 0; i < arr.length; i++)
        {
            for (var j = 0; j < str.length; j++)
            {
                if (arr[i] == str.charAt(j))
                {
                    return true;
                }
            }
        }   
        return false;
    }*/
    // 根据验证结果确认是否提交
    function check_submit()
    {
        if (flag == false)
        {
            return false;
        }
        return true;
    }
    </script>
    </head>
    </body>
    <script>
     var show_num = [];
     draw(show_num);
    function dj(){
     draw(show_num);   
     }
    function sublim(){
    var val=document.getElementById("text").value;  
                var num = show_num.join("");
                if(val==''){
                    alert('请输入验证码!');
                }else if(val == num){
                    alert('提交成功!');
                    document.getElementById(".input-val").val('');
                    draw(show_num);
    
                }else{
                    alert('验证码错误!\n你输入的是:  '+val+"\n正确的是:  "+num+'\n请重新输入!');
                    document.getElementById("text").value='';
                    draw(show_num);
                }
            
           
            
              }
    function draw(show_num) {
            var canvas_width=document.getElementById('canvas').clientWidth;
            var canvas_height=document.getElementById('canvas').clientHeight;
            var canvas = document.getElementById("canvas");//获取到canvas的对象,演员
            var context = canvas.getContext("2d");//获取到canvas画图的环境,演员表演的舞台
            canvas.width = canvas_width;
            canvas.height = canvas_height;
            var sCode = "1,2,3,4,5,6,7,8,9,0,q,w,e,r,t,y,u,i,o,p,a,s,d,f,g,h,j,k,l,z,x,c,v,b,n,m";
            var aCode = sCode.split(",");
            var aLength = aCode.length;//获取到数组的长度
                
            for (var i = 0; i <= 3; i++) {
                var j = Math.floor(Math.random() * aLength);//获取到随机的索引值
                var deg = Math.random() * 30 * Math.PI / 180;//产生0~30
                var txt = aCode[j];//得到随机的一个内容
                show_num[i] = txt;
                var x = 10 + i * 20;//文字在canvas上的x坐标
                var y = 20 + Math.random() * 8;//文字在canvas上的y坐标
                context.font = "bold 23px 微软雅黑";
    
                context.translate(x, y);
                context.rotate(deg);
    
                context.fillStyle = randomColor();
                context.fillText(txt, 0, 0);
    
                context.rotate(-deg);
                context.translate(-x, -y);
            }
            for (var i = 0; i <= 5; i++) { //验证码上显示线条
                context.strokeStyle = randomColor();
                context.beginPath();
                context.moveTo(Math.random() * canvas_width, Math.random() * canvas_height);
                context.lineTo(Math.random() * canvas_width, Math.random() * canvas_height);
                context.stroke();
            }
            for (var i = 0; i <= 30; i++) { //验证码上显示小点
                context.strokeStyle = randomColor();
                context.beginPath();
                var x = Math.random() * canvas_width;
                var y = Math.random() * canvas_height;
                context.moveTo(x, y);
                context.lineTo(x + 1, y + 1);
                context.stroke();
            }
        }
    function randomColor() {//得到随机的颜色值
            var r = Math.floor(Math.random() * 256);
            var g = Math.floor(Math.random() * 256);
            var b = Math.floor(Math.random() * 256);
            return "rgb(" + r + "," + g + "," + b + ")";
        }
    </script>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    
    </head>
    <body>
        <%
             Object message = request.getAttribute("message");
             if(message!=null && !"".equals(message)){
         
        %>
             <script type="text/javascript">
                  alert("<%=request.getAttribute("message")%>");
             </script>
        <%} %>
        <div align="center">
            <h1 style="color: black;">公文信息列表</h1>
            <a href="chenggong.jsp">返回主页</a>
            <table class="tb">
                <tr>
                    <td>id</td>
                    <td>公文类别</td>
                    <td>公文标题</td>
                    <td>公文信息</td>
                    
                    
                    
                    <td align="center" colspan="2">操作</td>
                </tr>
                <c:forEach items="${courses}" var="item">
                    <tr>
                        <td>${item.id}</td>
                        <td>${item.leibie}</td>
                        <td>${item.biaoti}</td>
                        <td>${item.main}</td>
                        
                        <td><a href="CourseServlet?method=getcoursebyid&id=${item.id}">修改</a></td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    
    </head>
    <body>
        <div align="center">
            <h1 style="color: black;">公文信息查询</h1>
            <a href="chenggong.jsp">返回主页</a>
            <form action="CourseServlet?method=search" method="post" onsubmit="return check()">
                <div class="a">
                    公文类别<input type="text" id="leibie" name="leibie"/>
                </div>
                <div class="a">
                    公文标题<input type="text" id="biaoti" name="biaoti" />
                </div>
                <div class="a">
                    公文内容<input type="text" id="main" name="main" />
                </div>
                
                <div class="a">
                    <button type="submit" class="b">&nbsp;&nbsp;&nbsp;</button>
                </div>
            </form>
        </div>
        <script type="text/javascript">
            function check() {
                var leibie = document.getElementById("leibie");;
                var main = document.getElementById("main");
                var biaoti = document.getElementById("biaoti");
                
                
                //非空
                
                }
            }
        </script>
    </body>
    </html>
    <%@ page language="java" contentType="text/html; charset=UTF-8"
        pageEncoding="UTF-8"%>
    <%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
    <!DOCTYPE html>
    <html>
    <head>
    <meta charset="UTF-8">
    <title>Insert title here</title>
    
    </head>
    <body>
        <div align="center">
            <h1 style="color: black;">信息列表</h1>
            <a href="chenggong.jsp">返回主页</a>
            <table class="tb">
                <tr>
                    <td>id</td>
                    <td>公文类别</td>
                    <td>公文标题</td>
                    <td>公文信息</td>
                </tr>
                <!-- forEach遍历出adminBeans -->
                <c:forEach items="${courses}" var="item" varStatus="status">
                    <tr>
                        <td>${item.id}</td>
                        <td>${item.leibie}</td>
                        <td>${item.biaoti}</td>
                        <td>${item.main}</td>
                    </tr>
                </c:forEach>
            </table>
        </div>
    </body>
    </html>

    以上实现了,登陆跳转和公文的增删改查。

  • 相关阅读:
    flex 均分铺满
    git commit -a -m "M 1、引入mixin,公共样式mixin传参处理;";git push origin master:master
    mixin 在传参中可以出现 参数 在类内部可以定义 作用域
    p:nth-last-child(2)
    display block 是否提倡
    对宽度的控制原则 git commit -a -m "M 1、完成less计算得出图片的均分布局;";git push origin master:master
    体验评分 小程序 优化
    tmp
    after
    通过less 计算 得出图片均分布局
  • 原文地址:https://www.cnblogs.com/520520520zl/p/12012411.html
Copyright © 2011-2022 走看看