JSP显示新闻

1.设计数据库,这里我使用的是MySql和Navicat可视化工具

用户表

JSP显示新闻

 

 

 新闻表

JSP显示新闻

 

 

 2.创建一个JAVAWEB项目

JSP显示新闻

 

 

 登录界面

JSP显示新闻

 

 

 登陆成功后

JSP显示新闻

 

 

 点击管理新闻

JSP显示新闻

 

 

点击查看

JSP显示新闻

 

 

 登录页面

<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="utf-8">
    <title>登录</title>
</head>
<script type="text/javascript" src="js/login.js"></script>
<body>
<header>
    <div class="logo">
        <img src="img/login_logo.png">
    </div>
    <div><a href="" class="help">帮助</a></div>
</header>

<main>
    <form id="login_form" action="login" method="post">
        <div class="login_box">
        <div class="login-head">
            <div class="login-title">登录</div>
            <div class="icon"></div>
        </div>
        <div class="login-content">
            <div id="tip">
                <br>
                <div class="user-login">用户登录</div>
            </div>
            <div>
                <input type="text" name="username" placeholder="用户名"  id="username">
            </div>
            <div>
                <input type="password" name="password" placeholder="密码" id="password">
            </div>
            <div>
                <div class="choose">学生选择@stu.swpu.edu.cn</div>
                <div><a href="" class="forget">忘记密码</a></div>
            </div>
            <div>
                <input type="submit" name="submit" value="登录" class="login" >
            </div>
        </div>
        </div>
    </form>
</main>
<footer>
    <div class="foot">西南石油大学</div>

</footer>
</body>
</html>

执行数据库操作

package DATA;

import java.sql.Connection;
import java.sql.DriverManager;
import java.sql.ResultSet;
import java.sql.Statement;

public class SqlHelper {
    public static Connection conn;
    private static String driverName = "com.mysql.jdbc.Driver";

    private static String dbURL = "jdbc:mysql://localhost:3306/new";

    private static String userName = "root";

    private static String userPwd = "root";

    private static Connection getConnection(){
        try {
            Class.forName(driverName);
            conn = DriverManager.getConnection(dbURL,userName,userPwd);
            return conn;
        }
        catch (Exception e){
            e.printStackTrace();
            System.out.println("连接失败");
        }
        return null;
    }
    public static ResultSet executeQuery(String SQL){
        try {
            Connection conn = getConnection();
            System.out.println("连接成功");
            Statement stmt = conn.createStatement();
            ResultSet rs = stmt.executeQuery(SQL);
            return rs;
        }
        catch (Exception e){
            e.printStackTrace();
            System.out.println("查询失败");
        }
        return null;
    }

    public static boolean executeUpdate(String SQL){
        try {
            Connection conn = getConnection();
            System.out.println("连接成功");
            Statement stmt = conn.createStatement();
            int result = stmt.executeUpdate(SQL);
            if (result>0)
                return true;
        }
        catch (Exception e){
            e.printStackTrace();
            System.out.println("更新失败");
        }
        return false;
    }
}

LoginServlet

JSP显示新闻

 

 

新闻列表页面

JSP显示新闻

 

 码云地址

https://gitee.com/TANGYILI/jspxianshixinwen

JSP显示新闻

上一篇:Spider--动态网页抓取--审查元素


下一篇:apache activemq——cve-2016-3088复现