📄 login.jsp
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" %>
<%@page import="java.sql.*"%>
<%@page import="java.io.*"%>
<%
String username="";
String pass="";
username=request.getParameter("username");
session.setAttribute("username1",request.getParameter("username"));
pass=request.getParameter("pass");
session.setAttribute("pass1",request.getParameter("pass"));
Connection conn=null;
Statement stmt=null;
ResultSet rs=null;
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
}
catch(ClassNotFoundException ce)
{
out.println(ce.getMessage());
}
try
{
conn=DriverManager.getConnection("jdbc:odbc:dong");
stmt=conn.createStatement(ResultSet.TYPE_SCROLL_INSENSITIVE, ResultSet.CONCUR_READ_ONLY);
String sql="select * from people where id='"+username+"'and pass='"+pass+"'";
rs=stmt.executeQuery(sql);
}
catch(SQLException e)
{
out.println(e.getMessage());
}if(rs==null)
{ out.print("结果集为空");}
else
{
if(!rs.next())
{
response.sendRedirect("2.jsp");
rs.close();
stmt.close();
conn.close();
}
//成功登陆
else
{
String sf=rs.getString("sf");
session.setAttribute("name2",sf);
session.setAttribute("name1",rs.getString("name"));
session.setAttribute("sql1","");
if(sf.equals("管理员"))
{
rs.close();
stmt.close();
conn.close();
response.sendRedirect("4.jsp");
}
else
{
rs.close();
stmt.close();
conn.close();
response.sendRedirect("9.jsp");
}
}
}
%>
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -