Solution:
//withdraw.jsp
<html>1. Save the file as withdraw.jsp in basic directory.
<head>
<title>MARKO</title>
</head>
<body>
<H1 align="center">MARKO Amount Withdrawal Screen</H1>
<%
String amt = request.getParameter("amt") ;
String balance = request.getParameter("bal");
if (amt == null)
{
%>
<form method="post">
<h3>
Your balance is <input type='text' readonly name='bal'
value='<%=balance%>'><br>
Please enter the amount to be withdrawn <input
type="text"
name="amt">
<input type="submit" value="Withdraw">
</form>
<%
}
else
{
%>
<jsp:useBean id="objW" class="MARKO.AccountBean"
scope="page" />
<jsp:setProperty name="objW" property="balance"
value="<%=balance%>"/>
<jsp:setProperty name="objW" property="amount"
value="<%=amt%>"/>
<H3 align="center">Rs. <%=amt%> withdrawn from your
account
the new balance is <jsp:getProperty name="objW"
property="balance"/>
</h3>
<%
}
%>
</body>
</html>
2. Open Notepad and enter the following code.
//AccountBean.java
package MARKO;3. Save the file as AccountBean.java in Session8 directory.
public class AccountBean implements java.io.Serializable
{
private int amount = 0;
private int balance = 0 ;
public String getAmount()// throws Exception
{
return String.valueOf(amount);
}
public void setAmount(String strAmt)// throws Exception
{
this.amount=Integer.parseInt(strAmt);
}
public String getBalance()
{
if (balance < amount)
{
return "Balance is not sufficient to withdraw money.";
}
else
{
balance = balance - amount;
}
return ("Rs."+String.valueOf(amount)+" withdrawn from your
account. The new balance is Rs"+String.valueOf(balance));
}
public void setBalance(String strBal)
{
balance = Integer.parseInt(strBal);
}
}
4. Stop and restart Tomcat server.
5. Open Internet Explorer and enter http://localhost:8080/Session8/withdraw.jsp in the browser.
The output appears as shown in Figure 8.6.
Enter an amount greater than the balance amount. A message will be displayed to the user informing that balance amount is insufficient.
Enter the amount to be withdrawn and click the Withdraw button. The output appears as shown in Figure 8.7 when you click on Withdraw button.
0 nhận xét:
Post a Comment