制作登录表单

1.制作一个登录表单,输入账号和密码,如果账号,密码相符,则显示“登陆成功”,否则显示“登录失败”。 

主要用<form></form>标签创建表单,然后用if...else...依次判断不同的账号密码情况。

2.在上题的表单中增加一个checkbox,让用户选择“是否注册为会员”,如果注册为会员,则在显示时增加文本“欢迎您注册为会员”。

主要用input里面的id属性,然后通过document.getElementById('id名')就可以获取到这个表单元素对象。

3.在页面1的表单内输入一个数字N,提交,能够在另一个页面打印N个“欢迎”字符串。

获取值并在新的页面里面写个for循环不断输出

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

要想在页面3里面获得1的内容,则要在页面2里面写两个type为hidden属性的文本框接受从1传过来的值,再通过2传到页面3.

全部代码如下

建立第一个jsp页面,question1.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    function func() {
        if (document.form1.account.value == document.form1.password.value
            && document.getElementById("register").checked) {
            window.alert("登录成功,欢迎您成为会员!");
            form1.submit();
            return;

        } else if (document.form1.account.value == document.form1.password.value) {
            window.alert("登录成功!");
            form1.submit();
            return;
        } else if(document.form1.password.value=="") {
            window.alert("密码不能为空!");
            return;
        }else if(document.form1.account.value==""){
            window.alert("账户不能为空!");
            return;
        }else{
            window.alert("账户和密码不相符!");
            return;
        }

    }

</script>
<%
    String str2 = "12";
    int number = Integer.parseInt(str2);

%>
<form name="form1" action="question12.jsp" method="post">
    账号<input type="text" name="account"><br>
    密码<input type="text" name="password"><br>
    <input id="register" type="checkbox">是否注册为会员<br>
    输入文本<input type="text" name="txt" value="<%=number%>"><br>
    <input type="button" onclick="func()" value="确定"><br>
</form>
</body>
</html>

建立第二个jsp页面,question12.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<script type="text/javascript">
    function func(){
        if(document.form2.username.value==""){
            window.alert("请输入用户名!");
            return;
        }else{
            form2.submit();
            return;
        }

    }
</script>
<%
    request.setCharacterEncoding("UTF-8");
    String account=request.getParameter("account");
    String password=request.getParameter("password");
    String N=request.getParameter("txt");
    int n=Integer.parseInt(N);
    for (int i = 0; i < n; i++) {
        out.println("欢迎!");
        out.println("<br>");

    }
%>


<form name="form2" action="question13.jsp" method="post">
    输入用户姓名:<input type="text" name="username"><br>
    <input type="button" value="提交" onclick="func()">
    <input type="hidden" name="account" value="<%=account%>"><br>
    <input type="hidden" name="password" value="<%=password%>"><br>
</form>
</body>
</html>

建立第三个jsp页面,question13.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body>
<%
    request.setCharacterEncoding("UTF-8");
    String account=request.getParameter("account");
    out.println("账户为:"+account);
    out.println("<br>");
    String password=request.getParameter("password");
    out.println("密码为:"+password);
%>
</body>
</html>

  • 0
    点赞
  • 7
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
制作一个美观的登录界面,可以采用以下步骤: 1. 创建一个HTML,并设置的样式。 2. 在中添加输入框和按钮等元素,并设置它们的样式。 3. 使用CSS样式来美化的外观,例如设置背景图像、颜色、字体等。 4. 可以使用JavaScript来添加一些交互效果,例如验证用户输入、显示提示信息等。 下面是一个简的HTML制作登录界面的例子: ```html <!DOCTYPE html> <html> <head> <title>Login Form</title> <style> body { background: #f2f2f2; font-family: Arial, sans-serif; } form { background: #fff; padding: 20px; border: 1px solid #ccc; margin: 100px auto; max-width: 400px; box-shadow: 0 0 10px rgba(0,0,0,0.2); } input[type="text"], input[type="password"] { padding: 10px; margin: 10px 0; border: none; border-bottom: 1px solid #ccc; width: 100%; box-sizing: border-box; font-size: 16px; } input[type="submit"] { background: #4CAF50; color: #fff; padding: 10px 20px; border: none; border-radius: 5px; cursor: pointer; font-size: 16px; margin-top: 20px; } input[type="submit"]:hover { background: #3e8e41; } </style> </head> <body> <form> <h2>Login Form</h2> <label for="username">Username:</label> <input type="text" id="username" name="username" placeholder="Enter your username"> <label for="password">Password:</label> <input type="password" id="password" name="password" placeholder="Enter your password"> <input type="submit" value="Login"> </form> </body> </html> ``` 你可以根据需要,调整样式和布局来实现更好的效果。

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值