• 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>

  • 相关阅读:
    马士兵讲jsp项目--BBS项目分析笔记
    ubuntu 14.04中安装phpmyadmin即mysql图形管理界面
    Xman冬令营writeup
    python--gevent协程及协程概念
    python--multiprocessing多进程总结
    python--threading多线程总结
    浅析Java中print、printf、println的区别
    内存泄漏与内存溢出
    Java中==和equals的区别,equals和hashCode的区别
    vue五十七:电影院售票项目案例之使用swiper实现轮播功能
  • 原文地址:https://www.cnblogs.com/yang--yang/p/4185872.html
Copyright © 2020-2023  润新知