网页特效phttp://www.111cn.net/网页特效p.html target=_blank >jsp教程用户登陆代码(完整登录实例)
这里我们提供了利用java来作用户登陆的代码,从html,到数据库教程以及jsp都一步步的写得很清楚的,如果你是jsp初学者来看看这款用户登陆是不是适合你吧,好了不说多了来看看这款用户登陆代码吧。
<form name="form1" method="post" action="login.jsp">
<p>
<label for="username"></label>
<input type="text" name="username" id="username">
</p>
<p>
<label for="passwrod"></label>
<input type="text" name="passwrod" id="passwrod">
</p>
<p>
<input type="submit" name="button" id="button" value="提交">
</p>
</form>
login.jsp代码
<%
string name = request.getparameter("username");
string pwd = request.getparameter("password");
//out.println(name+pwd);
string sql ="select * from info where username='"+name+"' and password='"+pwd+"'";
//out.println(sql);
statement stm= null;
resultset rs =null;
try
{
stm = conn.createstatement();
rs = stm.executequery(sql);
if(rs.next())
{
session.setattribute("username",name);
response.sendredirect("index.html");
}
else
{
response.sendredirect("index1.html");
}
}
catch(sqlexception e)
{
e.printstacktrace();
}
%>
info 表
create table if not exists `test` (
`id` int(8) not null auto_increment,
`username` char(150) default null,
`password` varchar(32),
`times` int(4) not null,
primary key (`id`)
) engine=myisam default charset=utf8 auto_increment=1 ;