JSp小程序编写

JSp小程序编写,第1张

你好,两个jsp文件,test02.jsp,test03.jsp.代码如下:

<%@ page contentType="text/htmlcharset=gb2312" %>

<%

String num = (String)request.getParameter("num")

try{

int n = Integer.parseInt(num)

if(n%2==0)

request.setAttribute("type","偶数")

else

request.setAttribute("type","奇数")

request.getRequestDispatcher("test03.jsp").forward(request,response)

}catch(Exception e){

e.printStackTrace()

}

%>

<%@ page contentType="text/htmlcharset=gb2312" %>

<% String type = (String)request.getAttribute("type")%>

<html>

<head><title>页面一</title></head>

<body>

<form action="test02.jsp" method="get">

请输入一个数字:<input type="text" name="num" />

<input type="submit" value="提交" />

</form>

${type }

</body>

</html>

Q5Action.jsp

<%@page language="java" contentType="text/htmlcharset=UTF-8" pageEncoding="UTF-8" %>

<%

String cashAmount = request.getParameter("cashamount")

String taxAmount = ""

if (cashAmount != null &&cashAmount.length() >0) {

int cash = Integer.parseInt(cashAmount)

if (cash >0 &&cash <= 10000) {

taxAmount += cash * 0.0205

} else if (cash >10000 &&cash <= 30000) {

taxAmount += cash * 0.0215

} else if (cash >30000) {

taxAmount += cash * 0.0250

}

}

%>

<html>

<head>

<title>ST8016 Assignment Q5</title>

<script type="text/javascript">

function verify() {

regExp = /\d+\b/

if (!(regExp.test(thisForm.cashamount.value))) {

alert("You must enter valid amount!")

return false}

return true

}

</script>

</head>

<body>

<h1>Assignment 1 - Question 5</h1>

<b>Tax Calculation</b>

<br /><br />

<table border="1" cellpadding="3">

<tr bgcolor="#EEEEEE"><td align="center">Amount</td><td align="center">Tax Rate %</td></tr>

<tr><td align="center">1 - 10,000 </td><td align="center">2.05 % (0.0205)</td></tr>

<tr><td align="center">10,001 - 30,000 </td><td align="center">2.15 % (0.0215)</td></tr>

<tr><td align="center">>30,000 </td><td align="center">2.50 % (0.0250)</td></tr>

</table>

<form name="thisForm" action="Q5Action.jsp" method=”post”

onsubmit="return verify()">

Amount: <input name=cashamount size=10 value="<%=cashAmount%>"/><br/><br/>

<input type=submit value="Calculate Tax Amount"/>

</form>

<% if (taxAmount.length() >0) {%>

<p>Tax Amount: <b><%=taxAmount%></b></p>

<% }%>

</body>

</html>

An error occurred at line: 3 in the jsp file: /example2_3.jsp

Syntax error on token "Invalid Character", expected

程序没问题,主要是有个符号"" 你弄成中文的";"了

就是下面这段:

double getLength(double a){

return 2*PI*a;

}

鉴定完毕!


欢迎分享,转载请注明来源:内存溢出

原文地址: http://outofmemory.cn/yw/11441519.html

(0)
打赏 微信扫一扫 微信扫一扫 支付宝扫一扫 支付宝扫一扫
上一篇 2023-05-16
下一篇 2023-05-16

发表评论

登录后才能评论

评论列表(0条)

保存