JSTL Web 应用程序开发
如何创建计算税费的 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我假设您是 JSP 新手,并且不知道如何开始。
以下是一个粗略指南:
HttpServletReques
t 类的request.getParameter(yourFormField)
方法。String
类的matches(pattern)
方法。I assume that you are new to JSP and you do not know how to get started.
Here is a rough guide:
request.getParameter(yourFormField)
method of theHttpServletReques
t class.matches(pattern)
method of theString
class.