【问题标题】:JSTL Web Application DevelopmentJSTL Web 应用程序开发
【发布时间】:2011-06-05 06:17:27
【问题描述】:

如何创建计算税金的 JSP 页面?我们必须使用正则表达式来验证用户输入。提交表单后,用户将看到税额。税金根据以下税表计算。您还需要将currencySymbol="$" 添加到<fmt:formatNumber> 标记中。

  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>

以上是我现在拥有的当前代码。有人可以帮我吗?

【问题讨论】:

    标签: java jstl retain


    【解决方案1】:

    我假设您是 JSP 新手并且不知道如何开始。 这是一个粗略的指南:

    1. 要检索用户输入:使用HttpServletRequest 类的request.getParameter(yourFormField) 方法。
    2. 要验证输入:使用String 类的matches(pattern) 方法。
    3. 计算您的输出(例如 taxRate)并将其显示在您的 JSP 页面中。

    【讨论】:

      猜你喜欢
      • 2011-09-22
      • 2010-12-02
      • 2018-03-04
      • 1970-01-01
      • 2011-06-02
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      相关资源
      最近更新 更多