login.jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head> <body>
<form action="chuandi.jsp" method="post">
<input type="text" name="userID" /><br />
<input type="password" name="password" /><br />
<input type="submit" value="submit" />
</form>
</body>
</html>chuandi.jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><%
String name = request.getParameter("userID");
String password = request.getParameter("password");
%><body>
<%
if(name.length() > 0 && password.length() > 0) {
%>
<jsp:forward page="success.jsp">
<jsp:param name="user" value="<%=name%>"></jsp:param>
<jsp:param name="passw" value="<%=password%>"></jsp:param>
</jsp:forward>
<%
}
else {
%>
<jsp:forward page="login.jsp"></jsp:forward>
<%
}
%>
</body>
</html>success.jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><%
String user = request.getParameter("user");
String pass = request.getParameter("passw");
%><body> 登录成功!<br /><br />
欢迎<%=user%>!<br /><br />
你的密码是:<%=pass%>
</body>
</html>
如何实现登录验证不成功后返回login.jsp页面时在login.jsp页面显示“登录失败,请重新登录”的字样啊?
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %><!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd"><html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title></title>
</head> <body>
<form action="chuandi.jsp" method="post">
<input type="text" name="userID" /><br />
<input type="password" name="password" /><br />
<input type="submit" value="submit" />
</form>
</body>
</html>chuandi.jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><%
String name = request.getParameter("userID");
String password = request.getParameter("password");
%><body>
<%
if(name.length() > 0 && password.length() > 0) {
%>
<jsp:forward page="success.jsp">
<jsp:param name="user" value="<%=name%>"></jsp:param>
<jsp:param name="passw" value="<%=password%>"></jsp:param>
</jsp:forward>
<%
}
else {
%>
<jsp:forward page="login.jsp"></jsp:forward>
<%
}
%>
</body>
</html>success.jsp:
<%@ page contentType="text/html; charset=gb2312" language="java" import="java.sql.*" errorPage="" %>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>无标题文档</title>
</head><%
String user = request.getParameter("user");
String pass = request.getParameter("passw");
%><body> 登录成功!<br /><br />
欢迎<%=user%>!<br /><br />
你的密码是:<%=pass%>
</body>
</html>
如何实现登录验证不成功后返回login.jsp页面时在login.jsp页面显示“登录失败,请重新登录”的字样啊?
你学了struts么,用struts来实现的话,思路要简单的多!逻辑都用在jsp界面中,很不好,可读性差,维护性也差!
如String erroNes = "登陆失败请从新登陆"
request.setAttribute("erro",erroNes)
然后存入request
jsp 页面
<h style="color:red">${erroNes }>