login_0002ejsp_jsp.java
资源名称:JSP02.rar [点击查看]
上传用户:top0756
上传日期:2022-08-11
资源大小:6501k
文件大小:6k
源码类别:
Jsp/Servlet
开发平台:
VBScript
- import java.sql.*;
- import java.util.*;
- import proj112.ISOtoGb2312 ;
- import javax.servlet.*;
- import javax.servlet.http.*;
- import javax.servlet.jsp.*;
- import org.apache.jasper.runtime.*;
- public class login_0002ejsp_jsp extends HttpJspBase {
- static {
- }
- public login_0002ejsp_jsp( ) {
- }
- private static boolean _jspx_inited = false;
- public final void _jspx_init() throws org.apache.jasper.runtime.JspException {
- }
- public void _jspService(HttpServletRequest request, HttpServletResponse response)
- throws java.io.IOException, ServletException {
- JspFactory _jspxFactory = null;
- PageContext pageContext = null;
- HttpSession session = null;
- ServletContext application = null;
- ServletConfig config = null;
- JspWriter out = null;
- Object page = this;
- String _value = null;
- try {
- if (_jspx_inited == false) {
- synchronized (this) {
- if (_jspx_inited == false) {
- _jspx_init();
- _jspx_inited = true;
- }
- }
- }
- _jspxFactory = JspFactory.getDefaultFactory();
- response.setContentType("text/html; charset=GB2312");
- pageContext = _jspxFactory.getPageContext(this, request, response,
- "", true, 8192, true);
- application = pageContext.getServletContext();
- config = pageContext.getServletConfig();
- session = pageContext.getSession();
- out = pageContext.getOut();
- // HTML // begin [file="/login.jsp";from=(0,51);to=(1,0)]
- out.write("rn");
- // end
- // HTML // begin [file="/login.jsp";from=(1,31);to=(2,0)]
- out.write("rn");
- // end
- // HTML // begin [file="/login.jsp";from=(2,27);to=(3,0)]
- out.write("rn");
- // end
- // HTML // begin [file="/login.jsp";from=(3,32);to=(4,0)]
- out.write("rn");
- // end
- // HTML // begin [file="/login.jsp";from=(4,42);to=(12,0)]
- out.write("rn<html>rn<head>rn<title>rn身份验证rn</title>rn</head>rn<body bgcolor="#ffffff">rn");
- // end
- // begin [file="/login.jsp";from=(12,2);to=(64,0)]
- 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";
- 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") ;
- }
- else if(select.equals("admin")){
- sql = "SELECT * FROM admin where name='"+user+"'and ad_password='"+pwd+"'";
- URL="admin.jsp";
- ResultSet rs = stmt.executeQuery(sql);
- if(rs.next()){
- request.getSession(true);
- session.setAttribute("id",user);
- response.sendRedirect(URL) ;}
- else
- response.sendRedirect("error.jsp") ;
- }
- //使用executeQuery执行SQL查询语句
- // end
- // HTML // begin [file="/login.jsp";from=(64,2);to=(68,0)]
- out.write("rnrn</body>rn</html>rn");
- // end
- } catch (Throwable t) {
- if (out != null && out.getBufferSize() != 0)
- out.clearBuffer();
- if (pageContext != null) pageContext.handlePageException(t);
- } finally {
- if (_jspxFactory != null) _jspxFactory.releasePageContext(pageContext);
- }
- }
- }