String name=(String)request.getParameter("name")
String pwd=(String)request.getParameter("pwd")
if("admin".equals(name) &&"admin".equals(pwd)){
response.sendRedirect("login.html?result=true")
}else{
response.sendRedirect("login.html?result=false")
}
%>
3个jsp文件,第一个是login.jsp,第二个是judge.jsp,第三个是afterLogin.jsp<%@ page language="java" contentType="text/htmlcharset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登录页面</title>
</head>
<body>
<form name="loginForm" method="post" action="judgeUser.jsp">
<table>
<tr>
<td>用户名:<input type="text" name="userName" id="userName"></td>
</tr>
<tr>
<td>密码:<input type="password" name="password" id="password"></td>
</tr>
<tr>
<td><input type="submit" value="登录" style="background-color:pink"> <input type="reset" value="重置" style="background-color:red"></td>
</tr>
</table>
</form>
</body>
</html>
<%@ page language="java" contentType="text/htmlcharset=GB18030"
pageEncoding="GB18030"%>
<%@ page import="java.util.*" %>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>身份验证</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030")
String name = request.getParameter("userName")
String password = request.getParameter("password")
if(name.equals("abc")&&password.equals("123")) {
%>
<jsp:forward page="afterLogin.jsp">
<jsp:param name="userName" value="<%=name%>"/>
</jsp:forward>
<%
}
else {
%>
<jsp:forward page="login.jsp"/>
<%
}
%>
</body>
</html>
<%@ page language="java" contentType="text/htmlcharset=GB18030"
pageEncoding="GB18030"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head>
<title>登录成功</title>
</head>
<body>
<%
request.setCharacterEncoding("GB18030")
String name = request.getParameter("userName")
out.println("欢迎你:" + name)
%>
</body>
</html>
欢迎分享,转载请注明来源:内存溢出
评论列表(0条)