javaweb学习第6篇 - 学会使用JSP+Servlet+Javabean模式进行简单的业务系统开发

目标:学会使用JSP+Servlet+Javabean模式进行简单的业务系统开发

新建两张父子表:1、学生表 2、学生发表的论文表

实现学生基本信息增删改查,针对某一个学生、对发表的论文进行增删改查,

说明:不允许使用其它框架,纯粹使用Model1(JSP+Servlet+Javabean)来进行开发
 

1.创建index.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<%@ page language="java" contentType="text/html; charset=utf-8"

    pageEncoding="utf-8" import="java.sql.*"%>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<style type = "text/css">

    a:link,a:visited{

        color:#0044DD;

        text:-decoration:none;}

    table th{

        color:#2467fa;

        background:#dadada;

        font-size:16px;

        border:1px solid #fffff;

    }

    table td{

        background:#dadada;

        text-align:center;

        border-align:1px solid #ffffff;

        }

  </style>

<title>主界面</title>

</head>

<body>

<div style="width:700px;margin:100px auto;text-align:center;line-height:100px;background:#ffffaa">

        <h1 style="font-family:仿宋">账号信息管理系统</h1>

   

    <table align="center" width="400px" border="1">

        <tr><th>用户名</th><th>密码</th><th>年龄</th><th>操作</th></tr>

        <%

            Class.forName("com.mysql.cj.jdbc.Driver");

            //Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root","root");

            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=utf-8&serverTimezone=GMT%2B8","root","laotu123");

            String sql = "select * from userinfo";

            Statement stmt = con.createStatement();

            ResultSet rs = stmt.executeQuery(sql);

            while(rs.next()) {

            %>

                <tr><td><%=rs.getString("name") %></td>

                <td><%=rs.getString("password") %></td>

                <td><%= rs.getInt("age") %></td>

                <td><button type = "button" onclick="alert('请先登陆!')">修改</button>

                    <button type = "button" onclick="alert('请先登陆!')">删除</button>

                </td>

                </tr>

            <%

                }

                rs.close();

                stmt.close();

                con.close();

               

             %>

    </table>

    <br>

    <button type = "button" align = "center" onclick="window.location.href='login.jsp'" ><h4>登陆</button>

    <br><br>

    </div>

</body>

</html>

 

2.创建login.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<%@ page language="java" contentType="text/html; charset=utf-8"

    pageEncoding="utf-8"%>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<style type = "text/css">

    a:link,a:visited{

        color:#0044DD;

        text:-decoration:none;}

    table th{

        color:#2467fa;

        background:#dadada;

        font-size:16px;

        border:1px solid #fffff;

    }

    table td{

        background:#dadada;

        text-align:center;

        border-align:1px solid #ffffff;

        }

  </style>

<title>登陆界面</title>

</head>

<body>

    <div style="width:700px;margin:100px auto;text-align:center;line-height:100px;background:#ffffaa">

        <h1 style="font-family:仿宋">账号信息管理系统</h1>

        <form name = "form1" action = "login_do.jsp" method="POST">

            <table align="center" width="300px" border="1">

            <tr><th>用户名</th>

                <td><input type = "text" name = "username"></td>

            </tr>

            <tr><th>密码</th>

                <td><input type = "password" name = "password"></td>

            </tr>

            <tr><th colspan = "2" align = "center"><input type = "reset" value = "重置" >

                <input type = "submit" value = "登陆"></th>

            </tr>

            </table>

        </form>

        <br>

    </div>

</body>

</html>

 

3.创建login_success.jsp

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">

<html>

<head>

<%@ page language="java" contentType="text/html; charset=utf-8"

    pageEncoding="utf-8" import="java.sql.*" %>

<meta http-equiv="Content-Type" content="text/html; charset=utf-8">

<style type = "text/css">

    a:link,a:visited{

        color:#0044DD;

        text:-decoration:none;}

    table th{

        color:#2467fa;

        background:#dadada;

        font-size:16px;

        border:1px solid #fffff;

    }

    table td{

        background:#dadada;

        text-align:center;

        border-align:1px solid #ffffff;

        }

  </style>

 

<title>登陆成功</title>

</head>

<body>

<%String name1 = (String)session.getAttribute("username");

    if(name1 == null) {

        String mgs = "您尚未登陆,请先登陆,3秒后跳转登陆界面!";%>

        <h1  align="center" />

            <%=mgs %>

    <%

        response.setHeader("Refresh", "3;login.jsp");

    }

    else{

    %>

    <div style="width:700px;margin:100px auto;text-align:center;line-height:100px;background:#ffffaa">

        <h1 style="font-family:仿宋">账号信息管理系统</h1>

        <h2 style="font-family:仿宋"><%=name1 %>,欢迎您!</h2>

   

    <table align="center" width="400px" border="1">

        <tr><th>用户名</th><th>密码</th><th>年龄</th><th>操作</th></tr>

        <%

            Class.forName("com.mysql.cj.jdbc.Driver");

            //Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/user","root","root");

            Connection con = DriverManager.getConnection("jdbc:mysql://localhost:3306/student?characterEncoding=utf-8&serverTimezone=GMT%2B8","root","laotu123");

            String sql = "select * from userinfo";

            Statement stmt = con.createStatement();

            ResultSet rs = stmt.executeQuery(sql);

            while(rs.next()) {

            %>

                <tr><td><%=rs.getString("name") %></td>

                <td><%=rs.getString("password") %></td>

                <td><%= rs.getInt("age") %></td>

                <td><input type="button" onclick="window.location.href='edit.jsp?name=<%=rs.getString("name") %>'" value="修改">

                    <a href="del.jsp?name=<%=rs.getString("name") %>" onclick="return confirm('确定删除吗?')"><input type = "button"  value="删除"></a>

                </td>

                </tr>

            <%

                }

                rs.close();

                stmt.close();

                con.close();

       

             %>

    </table>

    <br>

    <table align="center" >

        <tr>

           

            <td><input type="button" onclick="window.location.href='query_paper.jsp'" value="查询论文"></td>

            <td> &nbsp;</td>

            <td><input type="button" onclick="window.location.href='add.jsp'" value="增加用户"></td>

            <td> &nbsp;</td>          

            <td><input type="button" onclick="window.location.href='query.jsp'" value="查询用户"></td>

            <td> &nbsp;</td>

            <td><a href="login_out.jsp" onclick="return confirm('确定退出吗?')"><input type="button"  value="退出登陆"></a></td>

        </tr>

    </table>

  • 3
    点赞
  • 26
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值