JSP用户注册登陆注销JSP页面[1]
JSP用户注册登陆注销JSP页面[1]JAVA
【51Test.NET - JAVA】
JSP用户注册登陆注销JSP页面
一:JSP登陆页 login.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
登录页 - Java教程:http://www.javaweb.cc
<%
// 用户名:admin 密码:123
String name = request.getParameter("uname"); // 取得 name 的信息
String password = request.getParameter("upass"); // 取得 password 的信息
if(!(name == null || "".equals(name) || password == null || "".equals(password))) // 进行用户名和密码的验证
{
response.setHeader("refresh", "2; URL = welcome.jsp"); // 定时跳转
session.setAttribute("userid", name); // 登录成功的用户名保存在 session 中
%>
<%
}
else
{
%>
<%
}
%>
二、JSP登录成功页(欢迎页)welcome.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
登陆欢迎页 - Java中文网:http://www.javaweb.cc
<%
if(session.getAttribute("userid") != null) // 已经设置过的属性,所有不为空
{
%>
<%
}
else // 非法用户,没有登陆通过,则 session 范围内没有属性存在
{
%>
<%
}
%>
3、JSP注销页 logout.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<JAVA
一:JSP登陆页 login.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<%
// 用户名:admin 密码:123
String name = request.getParameter("uname"); // 取得 name 的信息
String password = request.getParameter("upass"); // 取得 password 的信息
if(!(name == null || "".equals(name) || password == null || "".equals(password))) // 进行用户名和密码的验证
{
response.setHeader("refresh", "2; URL = welcome.jsp"); // 定时跳转
session.setAttribute("userid", name); // 登录成功的用户名保存在 session 中
%>
用户登陆成功,两秒钟后跳转到欢迎页面!
如果没有自动跳转,请按这里
<%
}
else
{
%>
错误的用户名或密码!
<%
}
%>
二、JSP登录成功页(欢迎页)welcome.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<%
if(session.getAttribute("userid") != null) // 已经设置过的属性,所有不为空
{
%>
欢迎 <%= session.getAttribute("userid") %> 光临本站,您的 SessionID 为:<%= session.getId() %> 注销!
<%
}
else // 非法用户,没有登陆通过,则 session 范围内没有属性存在
{
%>
请您先登录!
<%
}
%>
3、JSP注销页 logout.jsp:
<%@ page contentType="text/html" pageEncoding="UTF-8" %>
<JAVA