java和sql登陆应用程序
2个回答
展开全部
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*,demo.*; " errorPage="" %>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登陆控制</title>
</head>
<body>
<%
request.setCharacterEncoding("gb2312");
String un=request.getParameter("tf1");
String ps=request.getParameter("tf2");
try{
Connection conn=DBConnection.getConnection();
Statement stmt=conn.createStatement();
String sql="select * from user where username='"+un+"'and password='"+ps+"'";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
out.print("恭喜你,登陆成功!");
session.setAttribute("name",un);
response.sendRedirect("index.jsp");
}else{
out.println("登陆错误,2秒后返回登陆页面!");
response.setHeader("Refresh","3; url=userLogin.jsp");
}
rs.close();
stmt.close();
conn.close();
} catch(Exception e){
out.print(e);
}
%>
</body>
</html>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>登陆控制</title>
</head>
<body>
<%
request.setCharacterEncoding("gb2312");
String un=request.getParameter("tf1");
String ps=request.getParameter("tf2");
try{
Connection conn=DBConnection.getConnection();
Statement stmt=conn.createStatement();
String sql="select * from user where username='"+un+"'and password='"+ps+"'";
ResultSet rs=stmt.executeQuery(sql);
if(rs.next()){
out.print("恭喜你,登陆成功!");
session.setAttribute("name",un);
response.sendRedirect("index.jsp");
}else{
out.println("登陆错误,2秒后返回登陆页面!");
response.setHeader("Refresh","3; url=userLogin.jsp");
}
rs.close();
stmt.close();
conn.close();
} catch(Exception e){
out.print(e);
}
%>
</body>
</html>
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询