login.jsp
<body>
<form action="checkLogin.jsp">
<table>
<tr><td>用户名:</td><td><input type="text" name="name"></td></tr>
<tr><td>密 码</td><td><input type="password" name="password"></td></tr>
<tr><td colspan="2"><input type="submit" value="提交"></td></tr>
</table>
</form>
</body>
checkLogin.jsp
<body>
<%
String name=(String)request.getParameter("name");
String password=(String)request.getParameter("password");
if(name.equals("admin")&&password.equals("admin")){
session.setAttribute("name",name);
session.setAttribute("password",password);
response.sendRedirect("success.jsp");
}else{
response.sendRedirect("error.jsp");
}
%>
</body>
success.jsp
<%
String name=(String)session.getAttribute("name");
String password=(String)session.getAttribute("password");
out.println("用户名:");
out.println(name);
out.println("<br>");
out.println("密码:");
out.println(password);
%>
<a href="buygoods.jsp">购买商品</a>
</body>
buygoods.jsp
<body>
<%
String name=(String)session.getAttribute("name");
String password=(String)session.getAttribute("password");
%>
你好<%=name %>sessionId<%=session.getId() %>
谢谢你购买本商品
<a href="logout.jsp">注销</a>
</body>
logout.jsp
<%
session.invalidate();
response.sendRedirect("login.jsp");
%>
count.jsp
<body>
<%
if(application.getAttribute("count")==null){
application.setAttribute("count",0);
}
Integer count=(Integer)application.getAttribute("count");
application.setAttribute("count",(Integer)(count.intValue()+1));
%>
你好,你是第<%=count %>个访问本站的人
</body>