我很难在我的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"> </td>
<td width="182"><label>
<button type="reset" class="">Cancel</button>
</label></td>
<td width="384"> <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);
}
豆类: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命名约定。尝试一致地在Tax和JSP类中的任何地方将实例变量AmountWithTax替换为amountWithTax。反射在这里有效,并且没有为字段AmountWithTax找到合适的get方法。