EL和JSTL的应用之项目优化

<%--
  Created by IntelliJ IDEA.
  User: uncle
  Date: 2021/2/9
  Time: 下午4:32
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
      <title>主页</title>
      <script type="text/javascript">
        window.onload = function () {
          var registButton = document.getElementById("regist");
          registButton.onclick = function () {
            window.location.href = "regist.jsp";
          }
        };
      </script>
    </head>
    <body>
        ${requestScope.result}
        <form action="login" method="post">
          账号:<input type="text" name="uname" value=""><br>
          密码:<input type="password" name="upassword" value=""><br>
              <input type="submit" value="登录"><br>
              <input id="regist" type="button" value="注册">
        </form>
    </body>
</html>

<%@ page import="java.util.ArrayList" %>
<%@ page import="domain.Kind" %><%--
  Created by IntelliJ IDEA.
  User: uncle
  Date: 2021/2/9
  Time: 下午8:07
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
    <head>
        <title>Title</title>

        <script type="text/javascript">
            window.onload = function () {
                var kindSelect = document.getElementById("kindSelect");
                kindSelect.onchange = function () {
                    window.location.href = "selectCommodity?kid="+this.value;
                }
            }

        </script>
    </head>
    <body>
        购物系统有商品种类如下,请下拉选择<br>
        <select id="kindSelect" name="kid">
            <option>==请选择==</option>
            <c:forEach var="kind" items="${requestScope.kindArrayList}">

                <option value="${kind.kid}">${kind.kname}</option>
            </c:forEach>
        </select>

    </body>
</html>

<%@ page import="java.util.ArrayList" %>
<%@ page import="domain.Commodity" %><%--
  Created by IntelliJ IDEA.
  User: uncle
  Date: 2021/2/9
  Time: 下午9:02
  To change this template use File | Settings | File Templates.
--%>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<html>
<head>
    <title>Title</title>
    <style type="text/css">
        tr {
            text-align:center;
        }
    </style>
    <script type="text/javascript">
        window.onload = function () {
            var buttonElements = document.getElementsByClassName("button");
            for (var i = 0; i < buttonElements.length; i++) {
                buttonElements[i].onclick = function () {
                    // formElement.action =  "saveCommodity?flag="+this.value;
                    var hiddentElement = document.getElementById("hidden");
                    hiddentElement.value = this.value;
                    var formElement = document.getElementById("form");
                    var formElement = document.getElementById("form");
                    formElement.submit();
                }
            }
        }
    </script>
</head>
<body>
    <form id="form" action="saveCommodity" method="post">
        <input id="hidden" type="hidden" name="flag" value="">
        <table border="1" align="center" width="60%" height="60%">
            <tr>
                <th></th><th>商品名称</th><th>商品单价</th>
            </tr>
            <c:forEach var="commodity" items="${requestScope.arrayList}">
                <tr>
                    <th><input type="checkbox" name="cid" value="${commodity.cid}"></th>
                    <th>${commodity.cname}</th>
                    <th>${commodity.cprice}</th>
                </tr>
            </c:forEach>
            <tr>
                <td colspan="3">
                    <input class="button" type="button" value="继续购物">
                    &nbsp;||&nbsp;
                    <input class="button" type="button" value="结算清单">
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

<%@ page import="domain.Commodity" %>
<%@ page import="java.util.ArrayList" %>

<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>

<html>
<head>
    <style type="text/css">
        td{
            text-align : center;
        }
    </style>
</head>
<body>
<table border="1" align="center" width="60%" height="60%">
    <tr>
        <th>商品名称</th><th>商品单价</th>
    </tr>
    <c:forEach var="commodity" items="${sessionScope.shoppingCar}">
        <tr>
            <td>${commodity.cname}</td>
            <td>${commodity.cprice}</td>
        </tr>
    </c:forEach>
    <tr>
        <td colspan="2">总计:${requestScope.sumPrice}</td>
    </tr>
</table>
</body>
</html>

<%--
  Created by IntelliJ IDEA.
  User: uncle
  Date: 2021/2/9
  Time: 下午6:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
    <head>
        <title>Title</title>
    </head>
    <body>
    尊敬的${param.uname}大人,您居然登录成功了<br>
    欢迎进入山寨购物系统,想买东西了么<br>
    如果想买,请点击&gt;&gt;<a href="selectAllKind" >进入</a>&lt;&lt;购物系统
    </body>
</html>

上一篇:js商品详情购买页增减数量


下一篇:阿里云官网文档勘误或补充,20160918