jsp登录界面+access

1、用户 登录 界面 log.jsp %@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" % !DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" " http://www.w3.org/TR/html4/loose.dtd " html head m

<link href="/js/syntaxhighlighter/SyntaxHighlighter.css" rel="stylesheet" type="text/css" />

1、用户登录界面log.jsp

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
http://www.w3.org/TR/html4/loose.dtd">


<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
用户登陆


<body>



用户名


密 码







2、处理用户登录的程序login.jsp

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<
%@include file="ConnDB.jsp"%>

http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<meta name="robots" content="noindex,nofollow" />
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<strong>登录</strong>检查

<body>
<%
String userName = request.getParameter("userName");
String Password = request.getParameter("Password1");

Statement stmt_Check=conn.createStatement();
String sql = "select * from admin where userPwd='"+ Password + "' and userName='" + userName +"'";
ResultSet RsLoginCheck = stmt_Check.executeQuery(sql);


if(RsLoginCheck.next())
{
out.print("成功");
// response.sendRedirect("index.jsp");
}
else
{
out.print("用户名或密码错误!!!");
}
%>






<%
//*********** 数据库关闭代码 *******************************
RsLoginCheck.close(); //关闭记录集对象
stmt_Check.close(); //关闭语句对象
conn.close(); //关闭连接对象
%>

3、数据插入Access,既注册newuser.jsp

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
http://www.w3.org/TR/html4/loose.dtd">


<meta http-equiv="Content-Type" content="text/html; charset=gb2312">
注册

<body>



用户名


密 码


确认密码

性别:






<script language=javascript type="text/javascript">

</script>

4、处理注册的程序act.jsp

<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<
%@include file="ConnDB.jsp"%>

<%
Statement st=conn.createStatement(ResultSet.TYPE_SCROLL_SENSITIVE,ResultSet.CONCUR_UPDATABLE);

ResultSet rs = st.executeQuery("select id from admin");
rs.last();
int no;
if(rs.getRow()!=0){
no=rs.getInt(1);
no++;
}else{no=1;}
rs.close();

request.setCharacterEncoding("gb2312");
String uN=request.getParameter("userName");
String Pwd=request.getParameter("Password1");
String sex=request.getParameter("sex");
String id=""+no;
out.print(id);
String sql="insert into admin values("+id+",'"+uN+"','"+Pwd+"','"+sex+"')";
st.executeUpdate(sql);
st.close();
conn.close();

out.print("成功");
//response.sendRedirect("index.jsp");
%>

5、链接数据库程序ConnDB.jsp

<%

String dbname = ""; //Acess 数据库用户名,没有则为空
String user = ""; //Acess 数据库密码,没有则为空
//数据库连接字符串
String url ="jdbc:odbc:Driver={Microsoft Access Driver (*.mdb)};DBQ=F://Tomcat 5.5//webapps//test//Database//#data.mdb";
//加载驱动程序
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
//建立连接
Connection conn= DriverManager.getConnection(url);
%>

郑重声明:本文版权包含图片归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们(delete@yzlfxy.com)修改或删除,多谢。

郑重声明:本文版权归原作者所有,转载文章仅为传播更多信息之目的,如作者信息标记有误,请第一时间联系我们修改或删除,多谢。

留言与评论(共有 0 条评论)
昵称:
匿名发表
   
验证码: