login_0002ejsp_jsp.java
上传用户:top0756
上传日期:2022-08-11
资源大小:6501k
文件大小:6k
源码类别:

Jsp/Servlet

开发平台:

VBScript

  1. import java.sql.*;
  2. import java.util.*;
  3. import  proj112.ISOtoGb2312  ;
  4. import javax.servlet.*;
  5. import javax.servlet.http.*;
  6. import javax.servlet.jsp.*;
  7. import org.apache.jasper.runtime.*;
  8. public class login_0002ejsp_jsp extends HttpJspBase {
  9.     static {
  10.     }
  11.     public login_0002ejsp_jsp( ) {
  12.     }
  13.     private static boolean _jspx_inited = false;
  14.     public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
  15.     }
  16.     public void _jspService(HttpServletRequest request, HttpServletResponse  response)
  17.         throws java.io.IOException, ServletException {
  18.         JspFactory _jspxFactory = null;
  19.         PageContext pageContext = null;
  20.         HttpSession session = null;
  21.         ServletContext application = null;
  22.         ServletConfig config = null;
  23.         JspWriter out = null;
  24.         Object page = this;
  25.         String  _value = null;
  26.         try {
  27.             if (_jspx_inited == false) {
  28.                 synchronized (this) {
  29.                     if (_jspx_inited == false) {
  30.                         _jspx_init();
  31.                         _jspx_inited = true;
  32.                     }
  33.                 }
  34.             }
  35.             _jspxFactory = JspFactory.getDefaultFactory();
  36.             response.setContentType("text/html; charset=GB2312");
  37.             pageContext = _jspxFactory.getPageContext(this, request, response,
  38.              "", true, 8192, true);
  39.             application = pageContext.getServletContext();
  40.             config = pageContext.getServletConfig();
  41.             session = pageContext.getSession();
  42.             out = pageContext.getOut();
  43.             // HTML // begin [file="/login.jsp";from=(0,51);to=(1,0)]
  44.                 out.write("rn");
  45.             // end
  46.             // HTML // begin [file="/login.jsp";from=(1,31);to=(2,0)]
  47.                 out.write("rn");
  48.             // end
  49.             // HTML // begin [file="/login.jsp";from=(2,27);to=(3,0)]
  50.                 out.write("rn");
  51.             // end
  52.             // HTML // begin [file="/login.jsp";from=(3,32);to=(4,0)]
  53.                 out.write("rn");
  54.             // end
  55.             // HTML // begin [file="/login.jsp";from=(4,42);to=(12,0)]
  56.                 out.write("rn<html>rn<head>rn<title>rn身份验证rn</title>rn</head>rn<body bgcolor="#ffffff">rn");
  57.             // end
  58.             // begin [file="/login.jsp";from=(12,2);to=(64,0)]
  59.                 
  60.                 String user=ISOtoGb2312.convert(request.getParameter("username"));
  61.                 String pwd=ISOtoGb2312.convert(request.getParameter("password"));
  62.                 String select=request.getParameter("select");
  63.                 String url ="jdbc:odbc:dsn112";
  64.                 String userName = "sa";
  65.                 String password = "";
  66.                 String URL="";
  67.                 String sql="";
  68.                 Connection conn = null;
  69.                 try {
  70.                  Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
  71.                                  } catch(ClassNotFoundException e) {
  72.                  out.println("加载驱动器类时出现异常");
  73.                  }
  74.                  try {
  75.                   conn = DriverManager.getConnection(url, userName, password);
  76.                  //创建Statement语句
  77.                                         }
  78.                                 catch(SQLException e) {
  79.                  out.println("连接数据库的过程中出现SQL异常<br>");
  80.                  }
  81.                  Statement stmt = conn.createStatement();
  82.                                         if(select.equals("student")){
  83.                  sql = "SELECT * FROM student where stu_id='"+user+"'and stu_password='"+pwd+"'";
  84.                                         URL="student.jsp";
  85.                                         ResultSet rs = stmt.executeQuery(sql);
  86.                                         if(rs.next()){
  87.                                           String a=rs.getString("stu_name");
  88.                                           request.getSession(true);
  89.                                           session.setAttribute("stu_name",a);
  90.                                           session.setAttribute("id",user);
  91.                                           response.sendRedirect(URL) ;}
  92.                                           else
  93.                                         response.sendRedirect("error.jsp") ;
  94.                                         }
  95.                 
  96.                                         else if(select.equals("admin")){
  97.                                          sql = "SELECT * FROM admin where name='"+user+"'and ad_password='"+pwd+"'";
  98.                                          URL="admin.jsp";
  99.                                          ResultSet rs = stmt.executeQuery(sql);
  100.                                        if(rs.next()){
  101.                                           request.getSession(true);
  102.                                           session.setAttribute("id",user);
  103.                                           response.sendRedirect(URL) ;}
  104.                                         else
  105.                                           response.sendRedirect("error.jsp") ;
  106.                                          }
  107.                 
  108.                                          //使用executeQuery执行SQL查询语句
  109.                 
  110.                 
  111.             // end
  112.             // HTML // begin [file="/login.jsp";from=(64,2);to=(68,0)]
  113.                 out.write("rnrn</body>rn</html>rn");
  114.             // end
  115.         } catch (Throwable t) {
  116.             if (out != null && out.getBufferSize() != 0)
  117.                 out.clearBuffer();
  118.             if (pageContext != null) pageContext.handlePageException(t);
  119.         } finally {
  120.             if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
  121.         }
  122.     }
  123. }