登录界面
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<form action="index.jsp">
用户名:<input type="text" name="uname">
<br>
密码:<input type="password" name="upwd">
<hr>
<input type="submit" value="登录">
<input type="reset" value="重置">
</form>
</body>
</html>
登录验证页面,可连接数据库
k<%
//接受数据
//接受用户名
String uname=request.getParameter("uname");
//接受密码
String umm=request.getParameter("mm");
//连接数据库
/*
request:请求
response:响应
session:会话
会话开始:打开浏览器
会话结束:关闭浏览器
application(服务器级):
跳转页面:
转发:request.getRequestDispatcher("index.jsp").forward(request,response);
转发带有数据:直接把请求对象和响应对象转发给目标页面
传递数据有效范围内:在两个页面之间有效
重定向:
response.sendRedirect("index.jsp");
重定向方式 跳转页面不带有数据
*/
if(uname.equals("admin")&&"123".equals(umm)){
//js跳转方式
//out.print("<script>location.href='index.jsp'</script>");
//转发
request.getRequestDispatcher("index.jsp").forward(request,response);
//把用户名放到request中
request.setAttribute("a", uname);
request.setAttribute("bbb", "吊塔");
//重定向
//response.sendRedirect("index.jsp");
}else{
//js跳转
out.print("<script>alert('账号或密码错误');location.href='login.jsp'</script>");
}
%>
转发页面index1.jsp
<html>
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<h1>欢迎:<%=request.getParameter("uname") %></h1>
<h1>欢迎:<%=request.getAttribute("a") %></h1>
<h1>欢迎:<%=session.getAttribute("bbb") %></h1>
<h2>
<a href="index2.jsp">走你</a>
</h2>
</body>
</html>
转发页面index2.jsp
<head>
<meta charset="utf-8">
<title>Insert title here</title>
</head>
<body>
<h2>欢迎老弟来<%=request.getParameter("uname") %></h2>
<h2>欢迎老弟来<%=request.getAttribute("a") %></h2>
<h2>欢迎老弟来<%=session.getAttribute("bbb") %></h2>
</body>
</html>