会员
周边
众包
新闻
博问
闪存
所有博客
当前博客
我的博客
我的园子
账号设置
简洁模式
...
退出登录
注册
登录
Xsi64's Blog
专注.NET技术
博客园
首页
新随笔
联系
订阅
管理
简单的JSP登录程序
HTML登录界面
<
html
>
<
head
>
<
title
>
登录
</
title
>
</
head
>
<
body
bgcolor
="#ffffff"
>
<
form
action
="chkLogin.jsp"
method
="POST"
>
<
input
type
="text"
name
="user"
/><
br
/>
<
input
type
="password"
name
="pass"
/><
br
/>
<
input
type
="Submit"
value
="提交"
/>
</
form
>
</
body
>
</
html
>
检查登录
<%
@ page contentType
=
"
text/html; charset=GBK
"
%>
<%
@ page
import
=
"
java.sql.*
"
%>
<
html
>
<
head
>
<
title
>
chkLogin
</
title
>
</
head
>
<
body bgcolor
=
"
#ffffff
"
>
<%
String user
=
request.getParameter(
"
user
"
);
String pass
=
request.getParameter(
"
pass
"
);
Connection con
=
null
;
PreparedStatement ps
=
null
;
ResultSet rs
=
null
;
try
{
Class.forName(
"
com.microsoft.jdbc.sqlserver.SQLServerDriver
"
);
con
=
DriverManager.getConnection(
"
jdbc:microsoft:sqlserver://localhost:1433;databasename=Test
"
,
"
sa
"
,
""
);
ps
=
con.prepareStatement(
"
SELECT * FROM [User] WHERE UserName=? AND UserPwd =?
"
);
ps.setString(
1
, user);
ps.setString(
2
, pass);
rs
=
ps.executeQuery();
if
( rs.next())
{
out.print(
"
登录成功!
"
);
}
else
{
out.print(
"
登录失败!
"
);
}
}
catch
(Exception ex)
{
ex.printStackTrace();
}
finally
{
if
(
null
!=
rs)
{
rs.close();
rs
=
null
;
}
if
(
null
!=
ps)
{
ps.close();
ps
=
null
;
}
if
(
null
!=
con)
{
con.close();
con
=
null
;
}
}
%>
</
body
>
</
html
>
posted @
2008-01-13 23:02
Xsi64
阅读(
833
) 评论(
0
)
编辑
收藏
举报
会员力量,点亮园子希望
刷新页面
返回顶部
公告