用jsp编写一个很简单的登陆页面
就一个很简单的,不要太难了,初学者能够接受的那种.非常感谢,要能连接数据库的那种,我用的是sqlserver数据库...
就一个很简单的,不要太难了,初学者能够接受的那种.
非常感谢,要能连接数据库的那种,我用的是sqlserver数据库 展开
非常感谢,要能连接数据库的那种,我用的是sqlserver数据库 展开
1个回答
展开全部
login.JSP
注: 由于时间仓促,程序可能有细小的问题!但绝对可以满足你的需要了!如果你知道JSP什么原理;那么小的问题不是什么问题了! 共同学习~~~
<%@ page contentType = "text/html;charset=GB2312" %>
<%@ page import = "java.sql.*" %>
<html>
<head>
<title></title>
</head>
<body bgcolor=LightBlue>
<div align="center">
<br>
<H1>欢迎光临企业办公平台</H1>
<form name="form1" method="post" action="" target="_self">
<table width="90%">
<tr>
<td width="50%" height="30" align="right">用户名:</td>
<td width="50%" height="30" align="left"> <input type="text" name="UserName"></td>
</tr>
<tr>
<td width="50%" height="30" align="right">密码:</td>
<td width="50%" height="30" align="left"> <input type="password" name="UserPassword"></td>
</tr>
<td width="100%" height="40" align="center" colspan="2">
<input type="submit" name="sub" value="登录">
</td>
</tr>
</table>
</form>
</div>
<% try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:a","root","database1");
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = null;
String name =new String(request.getParameter("
UserName").getBytes(“8859_1”));
String passwd =new String(request.getParameter("
UserPassword").getBytes(“8859_1”));
if(String_sql==null)
{
out.println("登陆名不可以为空");
out.println(“<HR>”);
}
else{
String_sql="select * from student where name ="+name+" and password="+psword+;
rs=stmt.executeQuery(String_sql)
while(rs.next())
{ out.println("登陆成功!");
out.println("您的用户名是:"+name)
out.println("您的密码是:"+password);
rs.close();
stmt.close();
conn.close();}
}
Catch( Exception e )
{out.println(“<font color=red size=5><B>”);
out.println(“出错了!”);
out.println(“</B></font>”);
}%>
</body>
</html>
注: 由于时间仓促,程序可能有细小的问题!但绝对可以满足你的需要了!如果你知道JSP什么原理;那么小的问题不是什么问题了! 共同学习~~~
<%@ page contentType = "text/html;charset=GB2312" %>
<%@ page import = "java.sql.*" %>
<html>
<head>
<title></title>
</head>
<body bgcolor=LightBlue>
<div align="center">
<br>
<H1>欢迎光临企业办公平台</H1>
<form name="form1" method="post" action="" target="_self">
<table width="90%">
<tr>
<td width="50%" height="30" align="right">用户名:</td>
<td width="50%" height="30" align="left"> <input type="text" name="UserName"></td>
</tr>
<tr>
<td width="50%" height="30" align="right">密码:</td>
<td width="50%" height="30" align="left"> <input type="password" name="UserPassword"></td>
</tr>
<td width="100%" height="40" align="center" colspan="2">
<input type="submit" name="sub" value="登录">
</td>
</tr>
</table>
</form>
</div>
<% try
{Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
Connection conn=DriverManager.getConnection("jdbc:odbc:a","root","database1");
Statement stmt = conn.createStatement(
ResultSet.TYPE_SCROLL_INSENSITIVE,
ResultSet.CONCUR_READ_ONLY);
ResultSet rs = null;
String name =new String(request.getParameter("
UserName").getBytes(“8859_1”));
String passwd =new String(request.getParameter("
UserPassword").getBytes(“8859_1”));
if(String_sql==null)
{
out.println("登陆名不可以为空");
out.println(“<HR>”);
}
else{
String_sql="select * from student where name ="+name+" and password="+psword+;
rs=stmt.executeQuery(String_sql)
while(rs.next())
{ out.println("登陆成功!");
out.println("您的用户名是:"+name)
out.println("您的密码是:"+password);
rs.close();
stmt.close();
conn.close();}
}
Catch( Exception e )
{out.println(“<font color=red size=5><B>”);
out.println(“出错了!”);
out.println(“</B></font>”);
}%>
</body>
</html>
参考资料: 费老劲了
本回答被提问者采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询