login.jsp~30~
资源名称:JSP02.rar [点击查看]
上传用户:top0756
上传日期:2022-08-11
资源大小:6501k
文件大小:2k
源码类别:
Jsp/Servlet
开发平台:
VBScript
- <%@ page contentType="text/html; charset=GB2312" %>
- <%@ page import="java.sql.*" %>
- <%@ page language="java" %>
- <%@ page import="java.util.*" %>
- <%@ page import=" proj112.ISOtoGb2312 "%>
- <html>
- <head>
- <title>
- 身份验证
- </title>
- </head>
- <body bgcolor="#ffffff">
- <%
- String user=ISOtoGb2312.convert(request.getParameter("username"));
- String pwd=ISOtoGb2312.convert(request.getParameter("password"));
- String select=request.getParameter("select");
- String url ="jdbc:odbc:dsn112";
- String userName = "sa";
- String password = "";
- String URL="";
- String sql="";
- Connection conn = null;
- try {
- Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
- } catch(ClassNotFoundException e) {
- out.println("加载驱动器类时出现异常");
- }
- try {
- conn = DriverManager.getConnection(url, userName, password);
- //创建Statement语句
- }
- catch(SQLException e) {
- out.println("连接数据库的过程中出现SQL异常<br>");
- }
- Statement stmt = conn.createStatement();
- if(select.equals("student")){
- sql = "SELECT * FROM student where stu_id='"+user+"'and stu_password='"+pwd+"'";
- URL="student.jsp";
- }
- else if(select.equals("admin")){
- sql = "SELECT * FROM admin where name='"+user+"'and ad_password='"+pwd+"'";
- URL="admin.jsp";
- }
- //使用executeQuery执行SQL查询语句
- ResultSet rs = stmt.executeQuery(sql);
- if(rs.next()){
- String a=rs.getString("stu_name");
- request.getSession(true);
- session.setAttribute("stu_name",a);
- session.setAttribute("id",user);
- response.sendRedirect(URL) ;}
- else
- response.sendRedirect("error.jsp") ;
- %>
- </body>
- </html>