javaBean作业之购书表单传值

1.题目

实现表单传值,(书名、单价、数量),通过实体类进行数据绑定及计算,最终显示总价等信息。

要求:总价计算需要用实体类进行计算

2.Books实体类

package com.hjj.book;

import lombok.Data;

import javax.annotation.sql.DataSourceDefinition;

/**
 * @author:嘉佳 Date:2023/10/8 15:16
 **/

public class Book {
    private double price;
    private int num;
    private String bookName;
    private double totalPrice;

    public double getPrice() {
        return price;
    }

    public void setPrice(double price) {
        this.price = price;
    }

    public int getNum() {
        return num;
    }

    public void setNum(int num) {
        this.num = num;
    }

    public String getBookName() {
        return bookName;
    }

    public void setBookName(String bookName) {
        this.bookName = bookName;
    }

    public double getTotalPrice() {
        return this.price*this.num;
    }

    public void setTotalPrice(double totalPrice) {
        this.totalPrice = totalPrice;
    }

}

3.表单信息录入order.jsp

<%@page contentType="text/html;charset=UTF-8"%>
<%@page pageEncoding="UTF-8"%>
<html>
<head>
    <meta charset="UTF-8">
    <title>信息录入</title>
</head>
<body>
<h2>请输入购书信息</h2>
<form method="post" action="javabean.jsp" >
    <label for="bookName">书名</label>
    <input type="text" name="bookName" id="bookName"  required><br/>
    <label for="price">单价</label>
    <input type="text" name="price" id="price" required><br/>
    <label for="num">数量</label>
    <input type="text" name="num" id="num" required><br/>
    <input type="submit" value="提交"/>
</form>
</body>
</html>

实施效果:

4.已录入信息展示javaBean.jsp

<%@page contentType="text/html;charset=UTF-8" %>
<%@page pageEncoding="UTF-8" %>
<%@page import="com.hjj.book.Book" %>
<html>
<head>
    <title>信息查看</title>
    <meta charset="UTF-8">
    <style>
        h2 {
            text-align: center;
        }

        table {
            /* 合并边框 */
            border-collapse: collapse;
            height: 80px;
            /* 居中 */
            margin: 0 auto;
        }

        th {
            /* 内边距 */
            padding: 5px 20px;
        }

        table, th, td {
            border: 1px solid #000;
        }
    </style>
</head>
<body>
<jsp:useBean id="Book" class="com.hjj.book.Book"></jsp:useBean>
<jsp:setProperty name="Book" property="*"/>
<h2>商品总价</h2>
<%
    request.setCharacterEncoding("UTF-8");
%>
<table>
    <tr>
        <th>书名</th>
        <th>价格</th>
        <th>数量</th>
        <th>总价</th>
    </tr>
    <tr>
        <td>
            <jsp:getProperty name="Book" property="bookName"/>
        </td>
        <td>
            <jsp:getProperty name="Book" property="price"/>
        </td>
        <td>
            <jsp:getProperty name="Book" property="num"/>
        </td>
        <td>
            <jsp:getProperty name="Book" property="totalPrice"/>
        </td>
    </tr>
</table>
</body>
</html>

实施效果:

 

 

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值