Jsp第八次作业
数据库test 中建个表 stu(stuid 主键 自动增长 ,用户名,密码,年龄)
CREATE TABLE stu ( uid INT auto_increment PRIMARY KEY, uname VARCHAR (10), upwd VARCHAR (10), uage INT );
1.设计一个注册页面,实现用户注册功能
2.设计一个登陆页面,实现用户名密码登陆
3.两个页面可以互相超链接
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title></title> </head> <body> <form action="ver.jsp" method="post"> <b>用户名</b> <input type="text" name="uname" /> <br /> <b>密码</b> <input type="text" name="upwd" /> <br /> <input type="submit" value="登录" /> <a href="reg.jsp">注册</a> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title>Insert title here</title> </head> <body> <h1>登录失败,3秒后返回登录界面</h1> <% response.setHeader("refresh", "3;url=login.jsp"); %> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title></title> </head> <body> <h1>登录成功</h1> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title></title> </head> <body> <form action="tiao.jsp" method="post"> <b>用户名</b> <input type="text" name="uname" /> <br /> <b>密码</b> <input type="text" name="upwd" /> <br /> <b>年龄</b> <input type="text" name="uage"/> <br /> <input type="submit" value="注册" /> <a href="login.jsp">登录</a> </form> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="Dao.biao1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title></title> </head> <body> <% String uname = request.getParameter("uname"); String upwd = request.getParameter("upwd"); String uages = request.getParameter("uage"); int uage = Integer.parseInt(uages); biao1 s1 = new biao1(); s1.reg(uname, upwd, uage); request.getRequestDispatcher("login.jsp").forward(request, response); %> </body> </html>
<%@ page language="java" contentType="text/html; charset=utf-8" pageEncoding="utf-8"%> <%@ page import="Dao.biao1"%> <!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=utf-8"> <title></title> </head> <body> <% String uname = request.getParameter("uname"); String upwd = request.getParameter("upwd"); biao1 s1 = new biao1(); if (s1.login(uname, upwd)) { request.getRequestDispatcher("main.jsp").forward(request, response); } else { request.getRequestDispatcher("cuowu.jsp").forward(request, response); } %> </body> </html>