【问题标题】:Communication problem between my Servlet, Beans and JSP我的 Servlet、Beans 和 JSP 之间的通信问题
【发布时间】:2019-09-07 17:08:18
【问题描述】:

我很难对我的 bean 进行计算并将结果显示在我的 JSP 文件中 当我执行我的代码时,我有一个异常:

org.apache.jasper.JasperException 有这行,问题所在行:<c:if test="${ !empty tax.AmountWithTax }"><c:out value="${ tax.AmountWithTax }" /></c:if>

错误信息:未找到 AmountWithTax 的属性

提前感谢您的帮助

JSP 表单源代码 SendStep1.jsp:

<form class="form-horizontal" action="../SendStep1/" name="amount-calculation-form" method="post">
<table   class="table table-striped table-hover">
  <tr>
    <td width="170"><strong>Amount Without Tax</strong></td>
    <td width="384">    <div class="col-sm-10">
    <input class="form-control" name="amount" placeholder="ex: 25000" value="" type="number"  id="amount"   maxlength="6" required>
</div></td>
    <td width="20">&nbsp;</td>
    <td width="182"><label>
      <button type="reset" class="">Cancel</button>
    </label></td>
    <td width="384">&nbsp;<label>
      <button type="submit" class="btn btn-primary">Make Calculation>></button>
    </label></td>
  </tr>
</form>

Servlet:SendStep1:

protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
    Tax tax = new Tax();
    tax.TaxCalculation(request);
    request.setAttribute("tax", tax);
    this.getServletContext().getRequestDispatcher( "../SendStep1.jsp" ).forward(request, response);
}

Beans:Tax.class

public class Tax {

    private int AmountWithTax;
    public void TaxCalculation(HttpServletRequest request) {
        int amount = Integer.parseInt(request.getParameter("amount"));

        if( amount <= 2000){
            AmountWithTax = amount + 30;
        }else if(amount <= 2500){
            AmountWithTax = amount + 60;
        }else if(amount <= 5000){
            AmountWithTax = amount + 75;
        }else if(amount <= 15000){
            AmountWithTax = amount + 150;
        }else if(amount <= 25000){
            AmountWithTax = amount + 450;
        }else if(amount <= 50000){
            AmountWithTax = amount + 750;
        }else if(amount <= 100000){
            AmountWithTax = amount + 1500;
        }else if(amount <= 250000){
            AmountWithTax = amount + 3000;
        }else if(amount <= 500000){
            AmountWithTax = amount + 5000;
        }else if(amount <= 600000){
            AmountWithTax = amount + 6000;
        }else if(amount <= 700000){
            AmountWithTax = amount + 7000;
        }else if(amount <= 800000){
            AmountWithTax = amount + 8000;
        }else if(amount <= 900000){
            AmountWithTax = amount + 9000;
        }else if(amount <= 1000000){
            AmountWithTax = amount + 10000;
        }else {
            AmountWithTax = amount + 50000;
        }
    }


    public int getAmountWithTax() {
        return AmountWithTax;
    }

    public void setAmountWithTax(int amountWithTax) {
        AmountWithTax = amountWithTax;
    }
}

【问题讨论】:

    标签: java jsp servlets javabeans


    【解决方案1】:

    您应该遵循 java 命名约定。尝试相应地将 Tax 和 JSP 类中的实例变量 AmountWithTax 替换为 amountWithTax。反射在这里有效,并没有为字段 AmountWithTax 找到合适的获取方法。

    【讨论】:

      猜你喜欢
      • 2011-01-25
      • 2012-08-02
      • 1970-01-01
      • 2012-03-17
      • 1970-01-01
      • 1970-01-01
      • 2020-07-15
      • 1970-01-01
      • 2010-10-12
      相关资源
      最近更新 更多