求jsp+access数据库 登录 注册 的源代码
1个回答
展开全部
登陆界面:
Index.jsp:
<%@ page contentType="text/html;charset=gb2312"%>
<form action="shujuku.jsp">
<h2>用户登录</h2>
用户名:<input type="text" name="userName">
<br>
密 码:<input type="password" name="userPass">
<br>
<input type="submit" value="登录">
<input type="reset" vallue="重置">
</form>
连接数据库:
Shujuku.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<html>
<body>
<%
String driverClass="sun.jdbc.odbc.JdbcOdbcDriver";
int i=0;
String path=request.getRealPath("");
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+path+"/db_database08.mdb";
String name=request.getParameter("userName");
String pass=request.getParameter("userPass");
String username=" ";
String password=" ";
Class .forName(driverClass);
Connection conn=DriverManager.getConnection(url,username,password);
Statement stmt=conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from tb_user");
while(rs.next()){
if(name.equals(rs.getString(2))&&pass.equals(rs.getString(3)))
{
out.println("登陆成功!");
i=1;}
}
if(i==0)
{out.println("登陆失败!");}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
Index.jsp:
<%@ page contentType="text/html;charset=gb2312"%>
<form action="shujuku.jsp">
<h2>用户登录</h2>
用户名:<input type="text" name="userName">
<br>
密 码:<input type="password" name="userPass">
<br>
<input type="submit" value="登录">
<input type="reset" vallue="重置">
</form>
连接数据库:
Shujuku.jsp
<%@ page language="java" import="java.sql.*" pageEncoding="gb2312"%>
<html>
<body>
<%
String driverClass="sun.jdbc.odbc.JdbcOdbcDriver";
int i=0;
String path=request.getRealPath("");
String url="jdbc:odbc:driver={Microsoft Access Driver (*.mdb)};DBQ="+path+"/db_database08.mdb";
String name=request.getParameter("userName");
String pass=request.getParameter("userPass");
String username=" ";
String password=" ";
Class .forName(driverClass);
Connection conn=DriverManager.getConnection(url,username,password);
Statement stmt=conn.createStatement();
ResultSet rs = stmt.executeQuery("select * from tb_user");
while(rs.next()){
if(name.equals(rs.getString(2))&&pass.equals(rs.getString(3)))
{
out.println("登陆成功!");
i=1;}
}
if(i==0)
{out.println("登陆失败!");}
rs.close();
stmt.close();
conn.close();
%>
</body>
</html>
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询