第十周jsp作业

5.4上机练习

数据库test 中建个表 stu(stuid 主键 自动增长 ,用户名,密码,年龄)

1.设计一个注册页面,实现用户注册功能
2.设计一个登陆页面,实现用户名密码登陆
3.两个页面可以互相超链接

<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="login04ok.jsp">
    <input name="name">name
    <input name="password">password
    
    <input type="submit" value="登录">
</form>
<a href="regist.jsp">注册</a>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
    <%@page import="java.sql.ResultSet"%>
<%@page import="a.BaseDao"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
    BaseDao baseDao = new BaseDao();
String name = request.getParameter("name");
String password = request.getParameter("password");

Object[] args = {name,password};
String sql = "select * from stu where name=? and password=?";
ResultSet resultSet = baseDao.query(sql, args);
if(resultSet.next()){
    baseDao.close();
    out.print("登录成功");
}else{
    response.encodeRedirectUrl("regist.jsp");
}

%>
</body>
</html>
<%@ page language="java" contentType="text/html; charset=utf-8"
    pageEncoding="utf-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<form action="regist1.jsp">
    <input name="name">name
    <input name="password">password
    <input name="age">age
    <input type="submit" value="注册">
</form>
</body>
</html>
<%@page import="java.sql.ResultSet"%>
<%@page import="a.BaseDao"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
    pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%

    BaseDao baseDao = new BaseDao();
String name = request.getParameter("name");
String password = request.getParameter("password");
String age = request.getParameter("age");
Object[] args = {name,password,age};
String sql = "insert into stu(name,password,age) values (?,?,?)";
baseDao.update(sql, args);
response.sendRedirect("login04.jsp");
%>
</body>
</html>

 

posted @ 2022-05-04 13:38  王玉宁325  阅读(20)  评论(0编辑  收藏  举报