zoukankan      html  css  js  c++  java
  • forward请求转发,param参数传递以及request.getParameter图文讲解

     1 <%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %>
     2 <!doctype html>
     3 <html>
     4     <head>
     5         <title>login</title>
     6         <meta http-equiv="content-type" comtent="text/html;charset=utf-8"/>
     7     </head>
     8     <body>
     9         <h1><font color="red">欢迎</font></h1>
    10         <form action="loginCheck.jsp" method="get">
    11             <table>
    12                 <tr>
    13                     <td>用户名:</td>
    14                     <td><input type="text" name="name" value=
    15                     "<%=request.getParameter("name")%>" /></td>
    16                 </tr>
    17                 <tr>
    18                     <td>密码:</td>
    19                     <td><input type="password" name="password"/></td>
    20                 </tr>
    21                 <tr>
    22                     <td><input type="submit" value="登录"/></td>
    23                 </tr>
    24             </table>
    25         </form>
    26     </body>
    27 </html>
    View Code
    <%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %>
    <!doctype html>
    <html>
        <head>
        <title>loginCheck</title>
        <meta http-equiv="content-type" content="text/html;charset=utf-8">
        </head>
        <body>
            <%
                String name = request.getParameter("name");
                String pass = request.getParameter("password");
            %>
            <%
                //if(name.equals("QQ") && password.equals("123"))
                if("QQ".equals(name) && "123".equals(pass))
            {
            %>
            <%--forward作用是转发客户端的请求 --%>
                    <jsp:forward page="success.jsp">
                    <jsp:param name="user" value="<%=name %>"/>
                    </jsp:forward>
            <% }
                else 
                %>
                <%{
                %>    <jsp:forward page="login.jsp">
                    <jsp:param name="name" value="<%=name %>"/>
                    </jsp:forward>
                <%}
                %>
                
        </body>
    </html>
     1 <%@ page language="java" contentType="text/html;charset=utf-8" pageEncoding="utf-8" %>
     2 <!doctype>
     3 <html>
     4     <head>
     5         <title>success</title>
     6         <meta http-equiv="content-type" content="text/html;charset=utf-8"/>
     7     </head>
     8     <body>
     9         <h2>登录成功</h2>
    10         <hr/>
    11         欢迎<%=request.getParameter("user")%>
    12     </body>
    13 </html>

  • 相关阅读:
    webpack的安装与配置
    npm初始化
    gitignore的配置
    git本地已有文件夹和远程仓库对应
    git 配置
    开发环境和开发工具
    git 码云使用教程
    递归
    LeetCode 392. 判断子序列
    MongoDB基本操作
  • 原文地址:https://www.cnblogs.com/yang--yang/p/4185872.html
Copyright © 2011-2022 走看看