基于JavaBean,JSP实现登录并显示分页信息的小系统(2)
try {
Class.forName("com.mysql.jdbc.Driver");
} catch (ClassNotFoundException e) {
e.printStackTrace();
}
Connection ct = DriverManager.getConnection(
"jdbc:mysql://localhost:3306/collage", "root", "");
Statement st = ct.createStatement();
ResultSet rs = st.executeQuery("select password from students where name='"
+ u + "'");
if (rs.next()) {
//说明用户名存在
if (rs.getString(1).equals(p)) {
//密码正确
response.sendRedirect("welcome.jsp?user=" + u);//跳转到欢迎界面并传递出用户名user
} else {
response.sendRedirect("login.jsp");
}
}
rs.close();
st.close();
ct.close();
*/
// 三、通过userbeanCl对用户进行验证
UserbeanCl ubc=new UserbeanCl();
if(ubc.checkUser(u,p))
{
response.sendRedirect("welcome.jsp?user=" + u);
}else {
out.println("<script>alert('密码或者用户名错误!');</script>");
Thread.sleep(1000);
response.sendRedirect("login.jsp");
// return;
}
%>
</center>
</body>
</html>
welcome页面:
<%@ page language="java" import="java.util.*,com.ly.model.*"
contentType="text/html; charset=UTF-8" pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Welcome your mother!</title>
</head>
<body>
<center>
Hello,world! <br>
<%=request.getParameter("user")%>
<br> <a href="login.jsp">返回重新登录</a>
<hr color="silver">
<br> 用户信息列表 <br>
<%
int pageNow=1;
String u=request.getParameter("user");
String s_pageNow=request.getParameter("pageNow");
if(s_pageNow!=null){
pageNow=Integer.parseInt(s_pageNow);
相关新闻>>
- 发表评论
-
- 最新评论 更多>>