编写一个JSP登录页面,可输入用户名和密码,提交请求到另一个JSP页面,该JSP页面获取请求的相关数据并显示出来。请求的相关数据包括用户输入的请求数据和请求本身的一些信息。

实战要求

编写一个JSP登录页面,可输入用户名和密码,提交请求到另一个JSP页面,该JSP页面获取请求的相关数据并显示出来。请求的相关数据包括用户输入的请求数据和请求本身的一些信息。

(例如请求使用的协议getProtocol()、请求的URI request.getServletPath()、请求方法request.getMethod()、远程地址request.getRemoteAddr()等)

 7.jsp  注意:(其中action对应的是另一个代码7.1.jsp名称)

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <style>
        .a{
            border-style: solid ;
            border-color: purple;
            width: 30%;
            height: 40%;
            margin: auto;
            /*position: absolute;*/
            /*left: 0;*/
            /*top: 0;*/
            /*bottom: 0;*/
            /*right: 0;*/
            background-color: lightgrey;
        }
        .b{
            text-align: center ;
            background-repeat: no-repeat ;
            background-position:center center;
            background-size:cover;
            background-attachment: fixed;
        }
    </style>
</head>
<body background="/photo/zhongguo3.jpg" class='b'>
<div align="center" class='a'>
    <form   name="form1" action="7.1.jsp" method="post">
        <h1 style="color: red">用户登录</h1>
        <h2>用户名:<input type="text" name="username"></h2>
        <h2>密&nbsp&nbsp&nbsp码:<input type="password" name="password"></h2>
        <h2><input type="submit" value="提交" style="margin-right: 50px">
            <input type="reset" value="取消"></h2>
    </form>
</div>
</body>
</html>

7.1.jsp

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
</head>
<body background="/photo/zhongguo2.jpg">
<div  align="center" >
<%--    color的颜色可自行设置--%>
    <h1 style="color: black">登录提交成功页面</h1>
    <hr size="2" color="blue">
    <h3>用户名:<%=request.getParameter("username") %></h3>
    <h3>密码:<%=request.getParameter("password") %></h3>
    <hr size="2" color="green">
    <h3>请求使用的协议:<%=request.getProtocol() %></h3>
    <h3>请求URL:<%=request.getServletPath() %></h3>
    <h3>请求方法:<%=request.getMethod() %></h3>
    <h3>远程地址:<%=request.getRemoteAddr() %></h3>
    <hr size="2" color="red">
</div>
</body>
</html>

展示结果:

 

  • 7
    点赞
  • 65
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
好的,我会尽量帮您解答这个问题。 首先,我们需要编写一个JSP登录页面,具体代码如下: ``` <!DOCTYPE html> <html> <head> <title>Login Page</title> </head> <body> <h1>Login Page</h1> <form action="process.jsp" method="post"> <label>Username:</label> <input type="text" name="username"><br><br> <label>Password:</label> <input type="password" name="password"><br><br> <input type="submit" value="Login"> </form> </body> </html> ``` 这个页面包含一个表单用户可以输入用户名密码,并点击登录按钮提交数据。 接下来,我们需要编写一个用于处理登录请求JSP页面,具体代码如下: ``` <!DOCTYPE html> <html> <head> <title>Process Login</title> </head> <body> <h1>Process Login</h1> <% String username = request.getParameter("username"); String password = request.getParameter("password"); %> <p>Username: <%= username %></p> <p>Password: <%= password %></p> <p>Protocol: <%= request.getProtocol() %></p> <p>URI: <%= request.getServletPath() %></p> <p>Method: <%= request.getMethod() %></p> <p>Remote Address: <%= request.getRemoteAddr() %></p> </body> </html> ``` 这个页面中,我们首先使用request.getParameter()方法获取用户提交用户名密码,然后使用JSP的内置对象request输出这些数据。同时,我们还输出了请求的协议、URI、请求方法和远程地址等信息。 最后,需要注意的一点是,为了保证安全性,我们应该对用户输入用户名密码进行校验和过滤,避免SQL注入等安全漏洞。 希望这个回答能够帮到您,如果还有任何问题,请随时提出。

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值