<%@ page contentType="text/html;charset=GB2312"%>
<%@ page import="java.sql.*"%>
<html>
<head>
<title>Java Web</title>
</head>
<body>
<%
Connection conn=null;
try
{
String uid=request.getParameter("uid");
String pwd=request.getParameter("pwd");
Class.forName("com.mysql.jdbc.Driver");
String url="jdbc:mysql://localhost:3306/news";
conn=DriverManager.getConnection(url,"root","123456");
Statement st=conn.createStatement();
ResultSet rs=st.executeQuery("select * from tb1");
while(rs.next())
{
String username=rs.getString(1);
String password=rs.getString(2);
}
if(username.equals(uid) && password.equals(pwd))
{
session.setAttribute("login","ok");
session.setMaxInactiveInterval(-1);
response.setStatus(HttpServletResponse.SC_MOVED_PERMANENTLY);
response.setHeader("Location","main.jsp");
}
else
{
out.println("用户名或密码输入错误!");
break;
}
}
catch(Exception e)
{
out.println("some error");
out.println(e.toString());
}
finally
{
conn.close();
}
%>
</body>
</html>浏览器报错如下:
添加回答
举报
0/150
提交
取消