开发者

JSTL Web Application Development

开发者 https://www.devze.com 2023-03-10 17:30 出处:网络
How do I create a JSP page that cal开发者_Python百科culates tax?We have to use regular expressions to validate the user input. After submitting the form, the user will see the tax amount. The tax is c

How do I create a JSP page that cal开发者_Python百科culates tax? We have to use regular expressions to validate the user input. After submitting the form, the user will see the tax amount. The tax is calculated based on the following tax table. You also need to add currencySymbol="$" to the <fmt:formatNumber> tag.

  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>

The above is the current code I have now. Can someone help me?


I assume that you are new to JSP and you do not know how to get started. Here is a rough guide:

  1. To retrieve user input: use the request.getParameter(yourFormField) method of the HttpServletRequest class.
  2. To validate the input: use the matches(pattern) method of the String class.
  3. Calculate your output (e.g. taxRate) and display it in your JSP page.
0

精彩评论

暂无评论...
验证码 换一张
取 消