好得很程序员自学网

<tfoot draggable='sEl'></tfoot>

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://HdhCmsTestw3.org/TR/html4/loose.dtd " html head m

1、用户 登录 界面 log.jsp


http://HdhCmsTestw3.org/TR/html4/loose.dtd ">



用户登陆






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


%@include file="ConnDB.jsp"%>

http://HdhCmsTestw3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd ">
http://HdhCmsTestw3.org/1999/xhtml ">



登录 检查


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


http://HdhCmsTestw3.org/TR/html4/loose.dtd ">



注册





function checkspace(checkstr) {
var str = '';
for(i = 0; i str = str + ' ';
}
return (str == checkstr);
}
function check()
{
if(checkspace(document.form1.userName.value)) {
document.form1.userName.focus();
alert("管理员用户名不能为空!");
return false;
}
if(checkspace(document.form1.Password1.value)) {
document.form1.Password1.focus();
alert("密码不能为空!");
return false;
}
if(checkspace(document.form1.Password1.value!=document.form1.Password2.value)){
document.form1.Password1.focus();
alert("两次密码不一样!");
return false;
}

document.form1.submit();
}
//-->

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


%@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);
%>

查看更多关于jsp登录界面+access的详细内容...

  阅读:35次