JSTL Web 应用程序开发

发布于 2024-11-13 23:27:57 字数 1541 浏览 1 评论 0原文

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

  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>

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

How do I create a JSP page that calculates 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?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

初见 2024-11-20 23:27:57

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

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

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.
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文