毕业设计-服务端

数据库连接-sqlite
private static Connection conn = null;
    private static final String DRIVER = "org.sqlite.JDBC";
    private static final String URL = "jdbc:sqlite:";
    private static final String FILENAME = "d:/graduation_examination.db3";
    public static Connection getConnection()
    {
        try
        {
            Class.forName(DRIVER).newInstance();
            conn = DriverManager.getConnection(URL + FILENAME);
            if (conn != null)
            {
                System.out.println("-----连接成功-----");
            }
        }
        catch (Exception e)
        {

            e.printStackTrace();
        }
        return conn;
    }

    public static void closeConn(Connection connection)
    {
        if (connection != null)
        {
            try
            {
                connection.close();
                connection = null;
            }
            catch (SQLException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }

    }

    public static void closePstmt(PreparedStatement pstmt)
    {

        try
        {
            if (pstmt != null)
            {
                pstmt.close();
                pstmt = null;
            }
        }
        catch (Exception e)
        {
            // TODO Auto-generated catch block
            e.printStackTrace();
        }

    }

    public static void closeRs(ResultSet rs)
    {

        try
        {
            if (rs != null)
            {
                rs.close();
                rs = null;
            }
        }
        catch (Exception e)
        {
            e.printStackTrace();
        }
    }

    public static void closeStmt(Statement stmt)
    {
        if (stmt != null)
        {
            try
            {
                stmt.close();
                stmt = null;
            }
            catch (SQLException e)
            {
                // TODO Auto-generated catch block
                e.printStackTrace();
            }
        }
    }


登录界面布局代码

<body bgcolor="#cac8ff" topmargin="100">

		<div align="center">

			<form name="login" method="get" action="Teacher/verify.jsp">

				<table width="480" border="0" cellspacing="1" cellpadding="1"
					class="tableBorder">
					<tr>
						<td height="34" colspan="2" align="center"
							background="/GraduationServer/images/login/login_bg3.gif"
							class="whitenormal">
							考试管理系统登录
						</td>
					</tr>
					<tr>
						<td height="134" colspan="2"
							background="/GraduationServer/images/login/login_bg1.gif"
							align="center">
							 
						</td>
					</tr>
					<tr>

						<td width="40%" align="right" class="normalText"
							background="/GraduationServer/images/login/login_bg3.gif">
							用户名:
						</td>
						<td width="60%"
							background="/GraduationServer/images/login/login_bg3.gif">
							<input type="text" name="username" class="textBox">
						</td>
					</tr>

					<tr>

						<td width="40%" align="right" class="normalText"
							background="/GraduationServer/images/login/login_bg3.gif">
							密  码:
						</td>
						<td width="60%"
							background="/GraduationServer/images/login/login_bg3.gif">
							<input type="password" name="password" class="textBox">
						</td>
					</tr>
					<tr>
						<td background="/GraduationServer/images/login/login_bg3.gif"
							align="right">
							<input type="submit" name="Submit" value="登录" />
						</td>

						<td background="/GraduationServer/images/login/login_bg3.gif"
							align="left">
							        
							<input type="reset" name="Reset" value="重置" />
						</td>
				</table>
			</form>
		</div>
		<iframe name='hideFrame' style="display: none"></iframe>
	</body>

登录验证代码实现

<%
    request.setCharacterEncoding("UTF-8");
    String strNextToPage = "main.jsp";
    String username = new String(request.getParameter("username")
            .trim().getBytes("ISO-8859-1"), "UTF-8");
    String password = new String(request.getParameter("password")
            .trim().getBytes("ISO-8859-1"), "UTF-8");

    String strMsgInfo = "";
    if (username.equals(""))
    {
        strMsgInfo = "请输入用户名!";
        out.println("<script>parent.alert('" + strMsgInfo
                + "')</script>");
        out
                .println("<script>history.back(1);</script>");
        return;
    }
    else if (password.equals(""))
    {
        strMsgInfo = "请输入密码!";
        out.println("<script>parent.alert('" + strMsgInfo
                + "')</script>");
        out
                .println("<script>history.back(1);</script>");
        return;
    }
    TeacherLoginBiz teacherLoginBiz = new TeacherLoginBizImpl();
    List<TeacherInfo> teacherInfos = teacherLoginBiz.loginTeacheBiz(
            username, password);

    if (teacherInfos.size() == 1)
    {

        Iterator<TeacherInfo> iterator = teacherInfos.iterator();
        while (iterator.hasNext())
        {

            TeacherInfo teacherInfo = iterator.next();

            System.out.println("-----id----"
                    + teacherInfo.getTeacher_id() + ";----name----"
                    + teacherInfo.getTeacher_name()
                    + ";-------pwd------"
                    + teacherInfo.getTeacher_pwd());

            session.setAttribute("username", teacherInfo
                    .getTeacher_name());
            session.setAttribute("password", teacherInfo
                    .getTeacher_pwd());
        }
    }
    else
    {
        strMsgInfo = "登录失败,用户名或密码错误!";
    }

    if (!strMsgInfo.equals(""))
    {
        out.println("<script>parent.alert('" + strMsgInfo
                + "')</script>");
        out
                .println("<script>parent.location.href='login.jsp';</script>");
        return;
    }
    out.println("<script>parent.location.href='" + strNextToPage
            + "';</script>");
%>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值