日期:2014-05-18  浏览次数:20651 次

求用JSP+SQL 做的登陆界面的例子
求用JSP+SQL   做的登陆界面的例子

------解决方案--------------------
a.jsp
<html>
<form name= "ff " action= "b.jsp ">
<input type= "text " name= "username ">
<input type= "password " name= "password ">
<input type= "submit " value= "登录 ">
</form>
</html>


b.jsp

<html>
<body>
<%
String un = request.getParamter( "username ");
String ps = request.getParamter( "password ");
Class.forName( "com.microsoft.jdbc.sqlserver.SQLServerDriver ");
Connection jdbcConn = DriverManager
.getConnection( "jdbc:microsoft:sqlserver://localhost:1433;DatabaseName=test ",
"sa ", "sa ");
Statement stmt = jdbcConn.createStatement();
ResultSet rs = stmt.executeQuery( "select * from t_user where username= ' "+un+ " ' and password= ' "+ps+ " ' ");
if(rs.next())
{
out.println( "登录成功! ");
}else
{
out.println( "登录失败! ");
}
%>
</body>
</html>


记得把数据库驱动包放到web-inf\lib里边去;当然b.jsp要把相关的类import进去

------解决方案--------------------
www.mldn.cn这里有几个视频.你可以看看.