html+jsp JDBC访问数据库的JavaBean配置实现其功能(实现登录和注册的访问)

s1.html
<!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>
<center>
<form method="post" action="s1.jsp">

 <table border="0" width="400" >
<tr><td>用户名:<td><input type="text" name="user">
<tr><td>密码:<td><input type="password" name="pass1" >
<tr><td colspan="2"><input type="submit" value="提交" >

</table>
</form>
</center>
</body>
</html>
s1.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!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>
<% String yhm,mm;
   yhm=request.getParameter("user");
   mm=request.getParameter("pass1");
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   Connection con=DriverManager.getConnection("jdbc:odbc:tableyh");
   Statement smt=con.createStatement();
   String sql="select * from [Sheet1$]";
   ResultSet rs=smt.executeQuery(sql);
   int f=0;
   while(rs.next())
   {//out.print(rs.getString("用户名")+"<br>");
     if(yhm.equals(rs.getString(1))&&mm.equals(rs.getString(2)))
     {f=1;break;}
   }
   if(f==1)out.print("登录成功");
   else
        out.print("密码不对");
   rs.close();
   smt.close();
   con.close();
%>
</body>
</html>
s2.html
<!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>
<center>
<form method="post" action="s2.jsp">

 <table border="0" width="400" >
<tr><td>用户名:<td><input type="text" name="user">
<tr><td>密码:<td><input type="password" name="pass1" >
<tr><td colspan="2"><input type="submit" value="提交" >

</table>
</form>
</center>
</body>
</html>
s2.jsp
<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<%@ page import="java.sql.*" %>
<!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>
<% String yhm,mm;
   yhm=request.getParameter("user");
   mm=request.getParameter("pass1");
   Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
   Connection con=DriverManager.getConnection("jdbc:odbc:tableyh");
   Statement smt=con.createStatement();
   String sql="insert into [Sheet1$] (用户名,密码) values('"+yhm+"','"+mm+"')";
   int a=0;
   a=smt.executeUpdate(sql);
   if(a>=1)out.print("success");
   else
       out.print("fail");
   smt.close();
   con.close();
   %>
0

Leave a Reply

Your email address will not be published.