jsp 在页面1中,输入账号密码,进行登录,如果账号密码相同,认为登录成功到页面2,页面2中显示一个文本框,用于输入用户姓名,输入之后,提交,在页面3中显示用户的账号和姓名

NewFile4.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<form name="loginForm" action="NewFile5.jsp" method="post">
    	账号:<input name="account" type="text"><br>
    	密码:<input name="password" type ="password"><br>
    	<input type="button" value="登录" onclick="validate()">
    </form>
    <script type="text/javascript">
    	function validate(){
    		if(loginForm.account.value!=loginForm.password.value){
    			alert("登录失败");return;
    		}
    		 loginForm.submit();
    	}
    </script>
</body>
</html>

NewFile5.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
	<%
		String str=request.getParameter("account");
	%>
	<form action="NewFile6.jsp" method="post">
		用户姓名:<input name="name" type="text"><br>
		<input type="submit" value="提交">
		<input name="account1" type="hidden" value="<%= str %>">
	</form>
</body>
</html>

NewFile6.jsp

<%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="UTF-8">
<title>Insert title here</title>
</head>
<body>
<%
	request.setCharacterEncoding("UTF-8");
	String str1=request.getParameter("account1");
	String str2=request.getParameter("name");
	out.println("用户账号:"+str1+"<br>"+"用户姓名:"+str2);
%>
</body>
</html>
  • 27
    点赞
  • 126
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
jsp页面添加一个按钮,并绑定一个点击事件,点击事件触发后,调用JavaScript函数弹出登录页面: <button onclick="showLogin()">登录</button> <script> function showLogin() { window.open("login.jsp","_blank","width=400,height=300"); } </script> 在login.jsp,添加一个表单用于输入账号密码,并绑定一个提交事件,提交事件触发后,调用Servlet程序进行登录验证: <form action="LoginServlet" method="post"> <label for="username">用户名:</label> <input type="text" id="username" name="username"><br> <label for="password">密码:</label> <input type="password" id="password" name="password"><br> <input type="submit" value="登录"> </form> 在LoginServlet,获取表单提交账号密码进行验证,如果验证通过,跳转到主页面;否则,返回登录页面并提示错误信息: public class LoginServlet extends HttpServlet { protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException { String username = request.getParameter("username"); String password = request.getParameter("password"); if (username.equals("admin") && password.equals("123456")) { // 验证通过,跳转到主页面 response.sendRedirect("index.jsp"); } else { // 验证失败,返回登录页面并提示错误信息 response.setContentType("text/html;charset=UTF-8"); PrintWriter out = response.getWriter(); out.println("<script>alert('用户名或密码错误!');</script>"); out.println("<script>window.location.href='login.jsp';</script>"); } } }
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值