2011-06-05 112 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页面中。