2011-06-05 156 views
-2

如何創建計算稅款的JSP頁面?我們必須使用正則表達式來驗證用戶輸入。提交表單後,用戶將看到稅額。稅率根據以下稅表計算。您還需要將currencySymbol="$"添加到<fmt:formatNumber>標記。JSTL Web應用程序開發

Total Income  Tax Rate 
    $1 - $5000   0% 
    $5001 - $20000  5% 
    $20001 and above  7% 

<%@taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%> 
<%@taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt"%> 
<html> 
    <head><title>Assignment One - Queston 4</title> 
    <script type="text/javascript"> 
    function verify() { 
    regExp = /\d+\b/; 
    if (!(regExp.test(thisForm.income.value))) { 
    alert("You must enter valid income amount!"); 
     return false;} 
     return true; 
     } 
    </script> 
    </head> 
    <body> 
    <fmt:setLocale value="en-US" /> 
    <c:set var="amount" value="${param.income}" /> 
     <c:if test='${empty param.income}'> 
     <c:set var="amount" value="0"/> 
     </c:if> 
     <b>Enter the amount of total income for this year:</b> 
     <form name="thisForm" action="Q4.jsp" method="post" 
      onsubmit="return verify();"> 
      Amount of sales:<input name=income size=10 value="?"> <br/><br/> 
      <input type=submit value="Calculate Tax"> 
     </form> 
<%-- Put Code to calculate the tax here --%> 
    </body> 
</html> 

以上是當前代碼我現在有。有人能幫我嗎?

回答

1

我認爲你是JSP新手,並且你不知道如何開始。 這裏是一個粗略的指導:

  1. 要檢索的用戶輸入:使用HttpServletReques噸類的request.getParameter(yourFormField)方法。
  2. 驗證輸入:使用String類的matches(pattern)方法。
  3. 計算您的輸出(例如taxRate)並將其顯示在JSP頁面中。