⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 chek_login.jsp

📁 jsp入门级代码
💻 JSP
字号:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="error.jsp" %>
<%
String ID = request.getParameter("ID");
String password = request.getParameter("password");
String info = "0";
Connection con = null;
Statement sm = null;
ResultSet rs = null;
try
{
    Class.forName("com.mysql.jdbc.Driver").newInstance();
    String url = "jdbc:mysql://localhost/mydb";
    con = DriverManager.getConnection(url,"root","12345");
    sm = con.createStatement();
    rs = sm.executeQuery("select * from users where USER_ID='"+ID+"'"); 
	if(rs.next())
	{
	   if(rs.getString("password").equals(password))
	   {
	       response.sendRedirect("index.jsp");
	       session.setAttribute("user",ID);
	   }
	   else
	       response.sendRedirect("login.jsp?info=2");
	}
	else
	{
	   response.sendRedirect("login.jsp?info=1");;
	}
}
catch(Exception e){
  e.printStackTrace();
}
 finally
 {
     if(rs!=null){
	    try{ rs.close();}catch(Exception e){e.printStackTrace();}
	  }
     if(sm!=null){
	    try{ sm.close();}catch(Exception e){e.printStackTrace();}
	  }	 
	  if(con!=null){
	    try{ con.close();}catch(Exception e){e.printStackTrace();}
	  } 
}
%>


⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -