JavaWeb.04.JPS登录注册------新闻发布系统01

一、登录

login

<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <link href="/web04/bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet">
    <script src="/web04/bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
    <script src="/web04/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
    <style>
        * {
            outline: none !important;
        }

        html,
        body {
            background: #1abe9c;
        }

        form {
            width: 300px;
            background: #ebeff2;
            box-shadow: 0px 0px 50px rgba(0, 0, 0, .5);
            border-radius: 5px;
            padding: 20px;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .btn-group {
            width: 100%;
        }

        .btn-group button {
            width: 50%;
        }
    </style>
</head>
<body>
<form action="dologin.jsp" method="post" id="myForm">
    <h3 class="text-center">欢迎使用🐖🐖🐖🐖新闻管理</h3>
    <div class="form-group">
        <input class="form-control" id="username" name="yh" placeholder="请输入您的账号" type="text">
    </div>
    <div class="form-group">
        <input class="form-control" id="password" name="mm" placeholder="请输入您的密码" type="password">
    </div>
    <div class="btn-group">
        <button class="btn btn-primary" type="submit">登录</button>
        <button class="btn btn-danger" onclick='location=href="regiest.jsp"' type="button">没有账号?</button>
    </div>
</form>
<script>

	$("#myForm").submit(()=>{
		if($("#username").val().length==0){
			alert("用户名不能为null")
			return false //不提交的
		}
		if($("#password").val().length==0){
			alert("密码不能为null")
			return false //不提交的
		}
		return true
	})

</script>
</body>
</html>


dolgin

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.Connection"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="oracle.jdbc.driver.OracleDriver"%>
<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%
	request.setCharacterEncoding("utf-8");
	String yh=request.getParameter("yh");
	String mm=request.getParameter("mm");

	//加载驱动
	Class.forName("oracle.jdbc.driver.OracleDriver");
	//定义连接字符串
	String url="jdbc:oracle:thin:@localhost:1521:orcl";
	//获得连接
	Connection con=DriverManager.getConnection(url,"数据库用户名","用户密码");
	//获得执行对象
	PreparedStatement ps=con.prepareStatement("select * from s_user where uname=? and upwd=?");
	ps.setString(1, yh);
	ps.setString(2, mm);
	//获得结果集
	ResultSet rs=ps.executeQuery();
	//判断结果
	if(rs.next()){
		// localhost:8080/web04/news/index.jsp
		request.getRequestDispatcher("/news/index.jsp").forward(request, response);
	}else
		response.sendRedirect("login.jsp");
	}
	//资源关闭
	if(con!=null&&!con.isClosed()){
		con.close();
	}
	if(ps!=null){
		ps.close();
	}
	if(rs!=null){
		rs.close();
	}
%>

二、新闻增加

<%@page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>bootstrap</title>
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <link href="/web04/bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet">
    <script src="/web04/bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
    <script src="/web04/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
    <style>
        * {
            outline: none !important;
        }

        body,
        html {
            background: #7f8d90;
        }

        nav,
        .breadcrumb {
            border-radius: 0 !important;
            margin-bottom: 0 !important;
        }

        .breadcrumb {
            margin-bottom: 20px !important;
            background: #36485c;
            color: white;
        }

        input,
        select,
        textarea,
        .panel-heading {
            border: none !important;
            border-radius: 0 !important;
        }

        .breadcrumb .active {
            color: yellow;
        }
    </style>
</head>

<body>
<nav class="navbar navbar-default hidden-sm hidden-xs">
    <div class="container-fluid">
        <div class="navbar-header">
            <a class="navbar-brand" href="/web04/news/index.html" style="font-size: 25px;">🐖🐖🐖🐖🐖</a>
        </div>
        <ul class="nav navbar-nav">
            <li class="dropdown">
                <a class="dropdown-toggle" data-toggle="dropdown">
                    新闻管理
                    <span class="caret"></span>
                </a>
                <ul class="dropdown-menu">
                    <li><a href="#">新闻发布</a></li>
                    <li class="divider"></li>
                    <li><a href="#">类别管理</a></li>
                </ul>
            </li>
        </ul>
        <ul class="nav navbar-nav navbar-right">
            <li><a>245@qq.com</a></li>
            <li><a href="#">退出<span class="glyphicon glyphicon-off"></span></a></li>
        </ul>
    </div>
</nav>

<ol class="breadcrumb">
    <li>您当前的位置是</li>
    <li>新闻发布系统</li>
    <li class="active">新闻发布</li>
</ol>

<form action="doAdd.jsp" class="container">
    <div class="panel panel-info">
        <div class="panel-heading">新闻标题</div>
        <input class="form-control" name="title" maxlength="50" placeholder="标题控制在30个字之内哦~~~" required>
        <div class="panel-heading">新闻类别</div>
        <select class=" form-control" name="topic">
            <option value="1">国际性新闻</option>
            <option value="2">国内性新闻</option>
            <option value="3">地方性新闻</option>
            <option value="4">典型新闻</option>
            <option value="5">综合新闻</option>
            <option value="6">文教新闻</option>
        </select>
        <div class="panel-heading">新闻作者</div>
        <input class="form-control" name="author" maxlength="10" placeholder="名字控制在10个字之内哦~~~" required>
        <div class="panel-heading">发布时间</div>
        <input class="form-control" name="publisher" required type="date">
        <div class="panel-heading">新闻内容</div>
        <textarea class="form-control" name="content" placeholder="~~~~这是必填的" required rows="10"></textarea>
        <div class="panel-footer">
            <button class="btn btn-primary">增加</button>
            <button class="btn btn-danger">取消</button>
        </div>
    </div>
</form>

</body>
</html>


doAdd

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%

	request.setCharacterEncoding("utf-8");
	//接受新闻的数据
	String title=request.getParameter("title");
	String author=request.getParameter("author");
	String publisher=request.getParameter("publisher");
	String topic=request.getParameter("topic");
	String content=request.getParameter("content");
	
	//新闻的添加(连接数据库)
	
	//加载驱动
	Class.forName("oracle.jdbc.driver.OracleDriver");
	//定义连接字符串
	String url="jdbc:oracle:thin:@localhost:1521:orcl";
	//获得连接
	Connection con=DriverManager.getConnection(url,"数据库用户名","用户密码");
	
	// 主键不能不填
	// 主键没有自增的选项(触发器+序列)
	//获得执行对象【数据插入之前,先把主键查询出来】
	PreparedStatement ps=con.prepareStatement("select nvl(max(news_id),0) from t_news");
	
	ResultSet rs=ps.executeQuery();
	
	int id=0;
	if(rs.next()){
		id=rs.getInt(1);//查询出来的最大id
	}
	id++; //为什么加一 【避免主键的重复】
	
	//插入新闻的操作
	ps=con.prepareStatement("insert into t_news(news_id, news_title, news_topic, news_author, news_publisher, news_content) values(?,?,?,?,?,?)");
	//赋值
	ps.setInt(1, id);
	ps.setString(2, title);
	ps.setInt(3, Integer.parseInt(topic));
	ps.setString(4, author);
	ps.setString(5, publisher);
	ps.setString(6, content);
	//执行结果
	int n=ps.executeUpdate();
	if(n>0){
		out.print("<script>alert('增加成功');location.href='/web04/news/index.jsp'</script>");
	}else{
		out.print("<script>alert('增加失败');location.href='/web04/news/index.jsp'</script>");
	}
	//资源的关闭
	if(con!=null&&!con.isClosed()){
		con.close();
	}
	if(ps!=null){
		ps.close();
	}
	if(rs!=null){
		rs.close();
	}
%>


三、注册

doRegiset

<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="java.sql.DriverManager"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<%

	request.setCharacterEncoding("utf-8");
	//接受新闻的数据
	String title=request.getParameter("title");
	String author=request.getParameter("author");
	String publisher=request.getParameter("publisher");
	String topic=request.getParameter("topic");
	String content=request.getParameter("content");
	
	//新闻的添加(连接数据库)
	
	//加载驱动
	Class.forName("oracle.jdbc.driver.OracleDriver");
	//定义连接字符串
	String url="jdbc:oracle:thin:@localhost:1521:orcl";
	//获得连接
	Connection con=DriverManager.getConnection(url,"sa","sa123");
	
	// 主键不能不填
	// 主键没有自增的选项(触发器+序列)
	//获得执行对象【数据插入之前,先把主键查询出来】
	PreparedStatement ps=con.prepareStatement("select nvl(max(news_id),0) from t_news");
	
	ResultSet rs=ps.executeQuery();
	
	int id=0;
	if(rs.next()){
		id=rs.getInt(1);//查询出来的最大id
	}
	id++; //为什么加一 【避免主键的重复】
	
	//插入新闻的操作
	ps=con.prepareStatement("insert into t_news(news_id, news_title, news_topic, news_author, news_publisher, news_content) values(?,?,?,?,?,?)");
	//赋值
	ps.setInt(1, id);
	ps.setString(2, title);
	ps.setInt(3, Integer.parseInt(topic));
	ps.setString(4, author);
	ps.setString(5, publisher);
	ps.setString(6, content);
	//执行结果
	int n=ps.executeUpdate();
	if(n>0){
		out.print("<script>alert('增加成功');location.href='/web04/news/index.jsp'</script>");
	}else{
		out.print("<script>alert('增加失败');location.href='/web04/news/index.jsp'</script>");
	}
	//资源的关闭
	if(con!=null&&!con.isClosed()){
		con.close();
	}
	if(ps!=null){
		ps.close();
	}
	if(rs!=null){
		rs.close();
	}
%>


regiset

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<head>
    <meta charset="UTF-8">
    <title>Document</title>
    <meta content="width=device-width, initial-scale=1" name="viewport">
    <link href="/web04/bootstrap-3.3.7-dist/css/bootstrap.css" rel="stylesheet">
    <script src="/web04/bootstrap-3.3.7-dist/js/jquery-3.5.1.js"></script>
    <script src="/web04/bootstrap-3.3.7-dist/js/bootstrap.js"></script>
    <style>
        * {
            outline: none !important;
        }

        html,
        body {
            background: #1abe9c;
        }

        form {
            width: 300px;
            background: #ebeff2;
            box-shadow: 0px 0px 50px rgba(0, 0, 0, .5);
            border-radius: 5px;
            padding: 20px;
            position: absolute;
            left: 50%;
            top: 50%;
            transform: translate(-50%, -50%);
        }

        .btn-group {
            width: 100%;
            margin-bottom: 15px;
        }

        .btn-group > * {
            width: 50%;

        }

    </style>
</head>

<body>
<form action="doRegiest.jsp" method="post" id="myForm">
    <h3 class="text-center">welcome🐖🐖🐖🐖注册</h3>
    <div class="form-group">
        <input class="form-control" id="username" name="yh" placeholder="请输入您的账号" required type="text">
    </div>
    <div class="form-group">
        <input class="form-control" id="password" name="mm" placeholder="请输入您的密码" required type="password">
    </div>
    <div class="btn-group" data-toggle="buttons">
        <label class="btn btn-primary active"><input checked name="xb" type="radio" value="男"></label>
        <label class="btn btn-primary"><input name="xb" type="radio" value="女"></label>
    </div>
    <div class="form-group">
        <input class="form-control" max="150" min="18" name="nl" placeholder="请输入您的年龄" required type="number">
    </div>
    <div class="btn-group">
        <button class="btn btn-primary" type="submit">注册</button>
        <button class="btn btn-danger" onclick='location=href="login.jsp"' type="button">已有账号?</button>
    </div>
</form>
</body>
</html>


四、重定向的页面跳转

/**
		(localhost:8080/web4/)跳转的时候:
			a.jsp 跳转到当前路径下的a.jsp(localhost:8080/web4/a.jsp)
			../a.jsp 跳转到上一级路径下的a.jsp(localhost:8080/a.jsp)
			/a.jsp 根目录的a.jsp (localhost:8080/a.jsp)
		**/
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值