jsp用户登录
下面展示一些 登录 代码。
login.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>用户登录</title>
</head>
<body>
<form action="check.jsp" method="post">
<input type="text" name="username"/><br>
<input type="password" name="pwd"/><br>
<input type="submit" value="提交"/>
<input type="reset" value="重置"/><br>
</form>
</body>
</html>
下面展示 确认 。
check.jsp :
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<%
String name=request.getParameter("username");
String password=request.getParameter("pwd");
%>
<%
if(name.equals("niudun12138")&&password.equals("123456")){
%>
<jsp:forward page="sus.jsp"></jsp:forward>
<%
}else{
%>
<jsp:forward page="fail.jsp"></jsp:forward>
<% } %>
</body>
</html>
下面展示 登录成功
。
sus.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<% String name=request.getParameter("username"); %>
恭喜<%=name %>登陆成功!
</body>
</html>
下面展示 登陆失败
。
fail.jsp:
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
很抱歉,登陆失败,请重新登录。
<a href="login.jsp">重新登陆</a>
</body>
</html>
实验截图: