<%@ page contentType="text/html" language="java" import="java.sql.*" errorPage="" pageEncoding="utf-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=utf-8" />
<title></title>
</head>
<body>
<%
//获取提交的用户名与密码
String username="";
String pwd="";
if (request.getParameter("username")!=null)
username=request.getParameter("username");
if (request.getParameter("pwd")!=null)
pwd=request.getParameter("pwd");
try
{
//1.注册数据库引擎
String JDriver="com.mysql.jdbc.Driver";//SQL数据库引擎
Class.forName(JDriver);
//2.连接数据库
//String url = "jdbc:mysql://localhost:3306;DatabaseName=class1";
String url = "jdbc:mysql://localhost:3306/class1";
Connection conn = DriverManager.getConnection(url, "root", "123456");
CallableStatement cs;
//3.通过调用存储过程查询并执行
cs = conn.prepareCall("{call userlogin(?,?,?)}");
cs.setString(1,username);
cs.setString(2,pwd);
cs.registerOutParameter(3, java.sql.Types.INTEGER);
cs.execute();
//4.处理查询结果
int num=0;//默认为零,即无此用户
num=cs.getInt(3);
if (num==1)//存在该用户
{
if(session.getAttribute("visited")==null){//判断是否session级变量visited为空,为空代表是第一次操作
session.setAttribute("visited","y");//置visited为可访问
session.setMaxInactiveInterval(60*60*24);
response.sendRedirect("question.jsp");//跳转到查询页面
}
else//说明已将viseited置为可访问,直接跳转到查询页面
response.sendRedirect("question.jsp");
}
else//不存在该用户,跳转到重新注册页面
{
response.sendRedirect("error.html");
}
conn.close();//关闭连接对象
}
catch(Exception ex)
{
out.println(ex.toString());//捕捉错误
}
%>
</body>
</html>
急求!!!!