开发实战练习1 jsp+jdbc 登陆程序
来源:互联网 发布:手机上做班服的软件 编辑:程序博客网 时间:2024/04/19 08:12
使用jsp+jdbc完成一个用户登陆程序,登录成功后可以使用session进行用户的登录验证,用户根据需要也可以直接进行系统的退出操作。本程序在mysql数据库里建立了一个member表。
mid varchar pk,
password varchar,
name varchar.
login.jsp:
<%@pagecontentType="text/html; charset=utf-8"%>
<html>
<head><title>登录页面</title></head>
<body>
<center>
<%=request.getAttribute("info")!=null?request.getAttribute("info"):""%>
<h1>登陆页面</h1>
<formaction="check.jsp"method="post">
用户名:<inputtype="text"name="mid"><br>
密 码:<inputtype="password"name="password"><br>
<inputtype ="submit"value="登录">
<inputtype ="reset"value="重置">
</form>
</center>
</body>
</html>
check.jsp:
<%@pagecontentType="text/html; charset=utf-8"%>
<%@pageimport="java.sql.*"%>
<html>
<head><title>验证页面</title></head>
<body>
<%!
publicstatic final String DBDRIVER ="org.gjt.mm.mysql.Driver";
publicstatic final String DBURL ="jdbc:mysql://localhost:3306/mysql";
public static final String DBUSER = "root";
public static final String DBPASS = "123456";
%>
<%
Connection conn = null;
PreparedStatement pstmt = null;
ResultSet rs = null;
boolean flag =false;
String name = null;
%>
<%
Class.forName(DBDRIVER);
conn = DriverManager.getConnection(DBURL,DBUSER,DBPASS);
String mid = request.getParameter("mid");
String password = request.getParameter("password");
String sql = "select name from member where mid=? and password=?";
pstmt = conn.prepareStatement(sql);
pstmt.setString(1, request.getParameter("mid"));
pstmt.setString(2, request.getParameter("password"));
rs = pstmt.executeQuery();
if(rs.next()){
session.setAttribute("id", mid);
flag = true;
}
rs.close();
pstmt.close();
conn.close();
%>
<%
if(flag){
%>
<jsp:forwardpage="welcome.jsp"/>
<%
}else{
request.setAttribute("info","错误的用户名或密码");
%>
<jsp:forwardpage="login_failure.jsp"/>
<%
}
%>
</body>
</html>
welcome.jp:
<%@pagecontentType="text/html; charset=utf-8"%>
<html>
<head><title>welcome</title></head>
<body>
<center>
<h1>登陆程序</h1>
<%
if(session.getAttribute("id")!=null){
%>
<h2>欢迎<fontcolor="RED"><%=session.getAttribute("id")%></font>光临!</h2>
<h3><ahref="logout.jsp">登陆注销</a></h3>
<%
}else{
request.setAttribute("info","请先登陆!");
%>
<jsp:forwardpage="login.jsp"/>
<%
}
%>
</center>
</body>
</html>
logout.jsp:
<%@pagecontentType="text/html; charset=utf-8"%>
<html>
<head><tile>logout</head>
<body>
<center>
<%
response.setHeader("refresh","2;URL=login.jsp");
session.invalidate();//让session失效
%>
<h3>您已经成功退出本系统,两秒后跳转回首页!</h3>
<h3>如果没有跳转,请按<ahref="login.jsp">这里</a></h3>
<center/>
</body>
</html>
- 开发实战练习1 jsp+jdbc 登陆程序
- java 用户登陆程序实现(jsp+jdbc)
- jsp:jdbc 数据库连接程序
- Jsp+Servlet+JavaBean+JDBC登陆实例
- JSP开发实战一
- 2009.6.24—JSP+JDBC练习
- hive jdbc程序开发
- JSP实战型程序连载
- 简单的登陆注册练习1 登陆
- JBuilder2005实战JSP之程序功能介绍(1)
- JBuilder2005实战JSP之程序功能介绍(1)
- 微信小程序开发实战
- JSP完成简单的登陆程序
- Qt实战开发-CSDN登陆界面布局
- [JSP]JDBC 用户登陆,查看修改添加用户
- 使用jsp+servlet+jdbc做的登陆注册案例
- jsp+servlet+jdbc实现简单的登陆验证
- SQL实战练习【1】
- HDU5379
- iOS QQ第三方登录 提示所安装的QQ不是最新版本的问题
- HDU 5249 KPI(treap 树堆 )
- Oracle 11G在用EXP 导出时,空表不能导出解决
- UIRefreshControl用法
- 开发实战练习1 jsp+jdbc 登陆程序
- easyui中combobox级联的实现
- ColorPicker 在sublime中的快捷键不可用(ctrl+shift+c)
- STM32的时钟基础知识
- 【数据结构】之队列的java实现(二)
- iOS 获取appstore 版本号
- Android微信内置浏览器 bootstrap vertical-align:middle 无效的问题
- TFT 学习笔记 1
- 环境加密与透明加密对比