zoukankan      html  css  js  c++  java
  • jsp3


    普通传值:

    a1.jsp

    <form action="a2.jsp" method="post">

    用户名:<input type="text" name="username" id="username"><br>

    密码:<input type="password" name="password"><br>

        <input type="submit">

    </form>

    a2.jsp

    <%

    String username = request.getParameter("username");

    String password = request.getParameter("username");

    %>

    欢迎<%=username %>

    <form action="a2.jsp" method="post">

    用户名:<input type="text" name="username" id="username"><br>

    密码:<input type="password" name="password"><br>

        <input type="submit">

    </form>

    String username = request.getParameter("username");

    String password = request.getParameter("password");

    if (username.equals("admin")&&password.equals("123456")){

        //登录成功

        response.sendRedirect("ok.jsp");

    }else{

        //登录失败

        response.sendRedirect("error.jsp");

    }

    %>

    在ok.jsp,已经无法取出传给a2.jsp中的username 


    <form action="a2.jsp" method="post">

    用户名:<input type="text" name="username" id="username"><br>

    密码:<input type="password" name="password"><br>

        <input type="submit">

    </form>


    <%

    String username = request.getParameter("username");

    String password = request.getParameter("password");

    if (username.equals("admin")&&password.equals("123456")){

        //登录成功

        //不影响客户端

        //response.sendRedirect("ok.jsp");

        //1、把请求转发给ok.jsp,不响应客户端,也不继续处理客户端请求

        //让ok.jsp对客户端进行响应

        request.getRequestDispatcher("ok.jsp").forward(request, response);

        //问题,地址栏会发生改变吗?

      不会

        //2、把数据也发一份给ok.jsp

    }else{

        //登录失败

        response.sendRedirect("error.jsp");

    }

    %>



     

    从页面上获取

    <%

    String username = request.getParameter("username");

    %>

    欢迎<%=username%>

     在a2.jsp设置属性

     request.setAttribute("classname", "S145班"); //key(关键字),value

    在ok.jsp中获取属性值

    <%
    String classname = request.getAttribute("classname").toString();
    %>
    <%=classname %>

    EL表达式

    ${classname}    //获取属性的值

    ${param.username}   //从页面上获取参数的值

    ${param.password}

  • 相关阅读:
    关于CSS/Grid Layout实例的理解
    关于对CSS position的理解
    接上一条博客
    搬迁声明
    自动化测试流程
    浏览器测试app-H5页面使用appium实现自动化
    RSA加密算法坑:pyasn1-error-when-reading-a-pem-string
    parameter/argument, Attribute/Property区别
    本地mysql用Navicat链接报错 Authentication plugin 'caching_sha2_password' cannot be loaded
    mysql安装忘记root密码,初始化密码
  • 原文地址:https://www.cnblogs.com/maoxiuying/p/9144319.html
Copyright © 2011-2022 走看看