Day18

index.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
pageContext.setAttribute("basePath", basePath);
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'index.jsp' starting page</title>

  </head>
  
  <body>
    <jsp:forward page="/servlet/ControlServlet">
        <jsp:param value="showIndex" name="op"/>
    </jsp:forward>
  </body>
</html>
View Code

login.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/header.jsp" %>
    <br/>
    <hr/>
    <br/>
           <form action="${basePath}servlet/ControlServlet?op=userLogin" method="post">
               <table border="1">
                   <tr>
                       <td>用户名:</td>
                       <td>
                           <input type="text" name="username">
                       </td>
                   </tr>
                   <tr>
                       <td>密码:</td>
                       <td>
                           <input type="password" name="password">
                       </td>
                   </tr>
                   <tr>
                       <td>角色:</td>
                       <td>
                           普通用户<input type="radio" name="type" value="普通用户" checked="checked" >
                           管理员<input type="radio" name="type"value="管理员" >
                       </td>
                   </tr>
                   <tr>
                       <td colspan="2">
                           <input type="submit" value="快速登录">
                       </td>
                   </tr>
               </table>
           </form>
  </body>
</html>
View Code

main.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%
String path = request.getContextPath();
String basePath = request.getScheme()+"://"+request.getServerName()+":"+request.getServerPort()+path+"/";
%>

<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
  <head>
    <base href="<%=basePath%>">
    
    <title>My JSP 'main.jsp' starting page</title>
    
    <meta http-equiv="pragma" content="no-cache">
    <meta http-equiv="cache-control" content="no-cache">
    <meta http-equiv="expires" content="0">    
    <meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
    <meta http-equiv="description" content="This is my page">
    <!--
    <link rel="stylesheet" type="text/css" href="styles.css">
    -->

  </head>
  
  <body>
   ${sessionScope.u.username} ,后台欢迎 <br>
  </body>
</html>
View Code

message.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/header.jsp" %>
  <!--
      此处的msg是在controlServlet中自个设置的一个标记;就是msg ,此处就取它。
      刀2   这种形式 专业术语称之为 “EL表达式”
  -->
       <center>
           <h1>    ${msg }</h1>
       </center>
  </body>
</html>
View Code

register.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/header.jsp" %>
    <br/>
    <hr/>
    <br/>
    <form action="${basePath}servlet/ControlServlet?op=userRegister"
        method="post">

        <table border="1">
            <tr>
                <td>用户名:</td>
                <td><input type="text" name="username">
                </td>
            </tr>
            <tr>
                <td>密码:</td>
                <td><input type="password" name="password">
                </td>
            </tr>
            <tr>
                <td>性别:</td>
                <td>
                    <input type="radio" value="man" name="sex"checked="checked"><input type="radio" value="woman" name="sex"></td>
            </tr>
            <tr>
                       <td>角色:</td>
                       <td>
                           普通用户<input type="radio" name="type" value="普通用户" checked="checked" >
                       </td>
                   </tr>
            <tr>
                <td colspan="2"><input type="submit" value="免费注册">
                </td>
            </tr>
        </table>

    </form>
</body>
</html>
View Code

showAllBooks.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/header.jsp" %>
<br/>
<br/>
   <a href="${basePath}"> 所有分类</a><c:forEach items="${cs}" var="c"  >
           <a href="${basePath}servlet/ControlServlet?op=showCategoryBooks&categoryId=${c.id}">${c.name}</a>
   </c:forEach>
   
       <table border="1" >
           <tr>
        <c:forEach items="${page.records}" var="b">
            <td><a
                href="${basePath}servlet/ControlServlet?op=showBookDetails&bookId=${b.id}">
                    <img src="${basePath}images${b.path}/${b.photoName}" width="100px"
                    height="100px"> </a><br /> 书名: ${b.name }<br /> 作者: ${b.author }<br />
                出版社: ${b.publish }<br /> 售价: ${b.price }<br /> <a
                href="${basePath}servlet/ControlServlet?op=showBookDetails&bookId=${b.id}">查看详细
            </a></td>
        </c:forEach>
    </tr>
       </table>
   <br/>
<br/>
   <%@ include file="/common/page.jsp" %>
  </body>
</html>
View Code

showBookDetails.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/header.jsp" %>
 <br/>
 <br/>
    <img src="${basePath}images${b.path}/${b.photoName}"
                width="100px" height="100px"> <br/><br/>
    
    ${b}
    
    <br/>
    <br/>
    <A href="${basePath}servlet/ControlServlet?op=buyBook&bookId=${b.id}">放入购物车</A>
    <A href="javascript:history.back()">继续购物</A>
  </body>
</html>
View Code

showCart.jsp

<%@ page language="java" import="java.util.*" pageEncoding="UTF-8"%>
<%@ include file="/header.jsp" %>
 <br> <br>
  <hr/>
     <c:if test="${empty sessionScope.cart.items}">
        <h2>对不起,你还没有买东西,请继续购买</h2>
    </c:if>
      
       <c:if test="${!empty sessionScope.cart.items}">
            <table border="1" width="438px" >
        
            <tr>
                <th>选择</th>
                <th>图书名称</th>
                <th>图书单价</th>
                <th>图书数量</th>
                <th>图书小计</th>
                <th>操作</th>
            </tr>
            <c:forEach items="${sessionScope.cart.items}" var="me" varStatus="vs"  >
                <tr class="${vs.index%2 ==0?'odd':'even' }">
                    <td>
                        <input type="checkbox" value="${me.key}" >
                    </td>
                    <td>${me.value.book.name}</td>
                    <td>${me.value.book.price}</td>
                    <td>
                        <input type="text" size="3" id="quantity" name="quantity" value="${me.value.quantity}" onchange="changeNum(this,'${me.key}',${me.value.quantity})" >
                    </td>
                    <td>${me.value.totalPrice}</td>
                    <td>
                        <a href="javascript:delOneItem('${me.key}')">删除</a>
                    </td>
                </tr>
            </c:forEach>
            <tr>
                <td colspan="6">
                共${sessionScope.cart.totalQuantity}件商品,总金额:${sessionScope.cart.amount}元  <a href="#">去支付</a>
                </td>
            </tr>
        </table>
       </c:if>
  </body>
</html>
<script type="text/javascript">
    // inputObj 客户端输入的数字
    // bookId 图书的编号
    // oldNum   以前的数量(未修改时!)
    function changeNum(inputObj,bookId,oldNum){
        var num = inputObj.value;
        //只能输入正整数
        if(!/^[1-9][0-9]*$/.test(num)){
            alert("请输入一个正确的数量");
            return;
        }
        
        
        
        var sure = window.confirm("确定要修改数量吗?");
        // 是否确定要修改
        if(sure){
        //确定
            window.location.href="${basePath}servlet/ControlServlet?op=changeNum&bookId="+bookId+"&num="+num;
        }else{
        //不确定
            inputObj.value= oldNum;
        }
    }
        function delOneItem(bookId){
            var sure = window.confirm("你确定要删除该项吗?");
            if(sure){
            window.location.href="${basePath}servlet/ControlServlet?op=delOneItem&bookId="+bookId
            }
        }
    
    
</script>
View Code

 

posted @ 2022-01-23 20:10  灰幕  阅读(30)  评论(0)    收藏  举报