Solution:
Enter the following code in the notepad and save the file as withdrawlstatus_1.jsp in Session8 folder.
//withdrawlstatus_1.jsp
<html>
<head>
<title>MARKO</title>
</head>
<body>
<H1 align="center">MARKO Withdrawal status checking
Screen</H1>
<form method ='post'>
<h3>User Email ID <input type='text' name='email'></h3>
<h3>Account no <input type='text' name='accNo'></h3>
<h3>Balance Amount <input type='text' name='Bal'></h3>
<input type='submit' value="Check Status">
</form>
<%
String strAccount = request.getParameter("accNo");
String strBal = request.getParameter("Bal");
String strEmail = request.getParameter("email");
if (strAccount == null || strBal == null || strEmail ==
null)
{
%>
<h3 align="center"> Please enter email address, account No
and Balance and click the Check Status button to compute
the withrawal status</h3>
<%
}
else
{
%>
<jsp:useBean id="objBT" class="MARKO.BankTransactionMail"
scope="session" >
<jsp:setProperty name="objBT" property="accountNo"
value="<%=strAccount%>"/>
<jsp:setProperty name="objBT" property="balance"
value="<%=strBal%>"/>
</jsp:useBean>
<h3>For Account no <jsp:getProperty name="objBT"
property="accountNo"/> :
<%
String strMessage = objBT.withdrawAllowed();
out.println(strMessage);
%>
<br>
<br>
<%=objBT.sendMail(strEmail,strMessage)%>
</h3>
<%
}
%>
</body>
Enter the following code in notepad and save the file as BankTransactionMail.java in Session8 folder.
//BankTransactionMail.java
package MARKO;
import javax.mail.*;
import javax.mail.internet.*;
import java.util.*;
public class BankTransactionMail implements java.io.Serializable
{
int intAccountNo;
int intBalance;
public String getBalance()
{
return String.valueOf(intBalance);
}
public void setBalance(String strBal)
{
intBalance = Integer.parseInt(strBal);
}
public String getAccountNo()
{
return String.valueOf(intAccountNo);
}
public void setAccountNo(String strAccNo)
{
intAccountNo = Integer.parseInt(strAccNo);
}
public String withdrawAllowed()
{
if (intAccountNo < 5000)
{
if (intBalance > 10000)
{
return "withdrawal is allowed!!!<br>To withdraw please
<a href='withdraw.jsp?bal= " +
String.valueOf(intBalance) + "'>click here.</a>";
//The file withdraw.jsp is created in Example 1
of Do It Yourself.
}
else
{
return "withdrawal is not allowed!!!";
}
}
else
{
return "withdrawal is allowed!!!<br>To withdraw please <a
href='withdraw.jsp?bal=" + String.valueOf(intBalance) +
"'>click here.</a>";
//The file withdraw.jsp is created later in Do it
Yourself part.
}
}
public String sendMail(String strTo,String strMsg)
{
String result = "<BR><BR><BR>";
String host = "Name_of _Machine_Running_SMTP_Service";
Properties prop = System.getProperties();
prop.put("libmail.n-syst.com", host);
Session session = Session.getDefaultInstance(prop, null);
session.setDebug(true);
try
{
MimeMessage msg = new MimeMessage(session);
msg.setFrom(new InternetAddress("admin@MARKO.com"));
msg.setRecipients(Message.RecipientType.TO,
InternetAddress.parse(strTo, false));
msg.setSubject("Automated Mail from MARKO JSP Page");
MimeBodyPart mbp = new MimeBodyPart();
mbp.setText(strMsg);
Multipart mp = new MimeMultipart();
mp.addBodyPart(mbp);
msg.setContent(mp);
msg.setSentDate(new Date());
Transport.send(msg);
result = result + "<H3 align='center'>Mail was
successfully sent to </B></FONT>: "+ strTo +"<BR>";
result = result+"</H3>";
}
catch (MessagingException ex)
{
result = result + "<H3 style='color:red'
align='center'>Error : </B><BR><HR> "+"<FONT SIZE=3
COLOR=\"black\">"+ex.toString()+"<BR><HR></h3>";
}
catch (Exception e)
{
result = result + "<H3 style='color:red'
align='center'>Error : </B><BR><HR> "+"<FONT SIZE=3
COLOR=\"black\">"+e.toString()+"<BR><HR></h3>";
}
finally
{
return result;
}
}
}
Enter the path http://localhost:8080/Session8/withdrawlstatus_1.jsp in the address bar. The output appears as shown in Figure 8.1.
Enter the e-mail Id, account number, and balance amount and click the Check Status button. The output appears as shown in Figure 8.2.
The automated mail sent to the user appears as shown in Figure 8.3.
To withdraw, click on the link provided in the figure above. The output appears as shown in Figure 8.4.
Enter the amount to be withdrawn and click the Withdraw button. The output appears as shown in Figure 8.5.
0 nhận xét:
Post a Comment