zoukankan      html  css  js  c++  java
  • jsp中的request.setAttribute的使用

    1.第一个jsp页面

    <form id="form1" method="post" action="first.jsp">
    <input type="text" name="balance"> <input type="submit"
    value="提交">
    </form>


    2.第二个jsp页面,根据第一个页面提交的balance的值,如果是小雨500,则在第一个页面处理,否则转发给第二个页面,其中使用setAttribute设置参数

    <body>
    <%
    String bal = request.getParameter("balance");
    double piaozi = Double.parseDouble(bal);
    if (piaozi < 500) {
    out.println("给你" + piaozi + "元");
    out.println("剑豪" +piaozi + "元");
    } else {
    List<String> info = new ArrayList<String>();
    info.add("1111");
    info.add("2222");
    info.add("3333");
    request.setAttribute("info", info);
    %>
    <jsp:forward page="second.jsp" />
    <%
    }
    %>
    </body>

    3.第三次页面,使用request.getAttribute获取属性


    <body>
    <%
    String bal = request.getParameter("balance");
    double piaozi = Double.parseDouble(bal);
    if (piaozi < 500) {
    out.println("给你" + piaozi + "元");
    out.println("剑豪" +piaozi + "元");
    } else {
    List<String> info = new ArrayList<String>();
    info.add("1111");
    info.add("2222");
    info.add("3333");
    request.setAttribute("info", info);
    %>
    <jsp:forward page="second.jsp" />
    <%
    }
    %>
    </body>


    4. 在一个页面输入600结果如下

    1111
    2222
    3333
    给您600.0元 减少600.0元

  • 相关阅读:
    sql server mdx
    mysql 按照 汉字的第一个拼音排序
    转,mysql的select * into
    mysql 日期的操作
    google 地图api
    ip_test
    AJAX (转w3cschool)
    jquery ajax 失败
    安装AdventureWorks2008R2示例数据库
    弹出新的网页窗口 js
  • 原文地址:https://www.cnblogs.com/shugen/p/6863033.html
Copyright © 2011-2022 走看看