Solution:
The files used to run the application are:
1. home.jsp
2. acclosure.jsp
3. MainServlet.java
<html>
<head>
<title> home </title>
</head>
<body>
<%
String userName = (String)session.getAttribute("UserName");
%>
<h3 align ='center'>Welcome <%=userName%> </h3>
While you are at the home page of MARKO Bank, please select
any of the option given below<br>
<br><br>
<a href="redirecterServlet?action=Withdrawal">Withdrawal<a>
<br>
<a href="redirecterServlet?action=deposit">Deposit<a>
<br>
<a href="redirecterServlet?action=chq">Request for cheque
book</a>
<br>
<a href="redirecterServlet?action=acclosure">Request for
Account Closure</a>
<br>
</body>
</html>
Update the home.jsp page with hyperlinks for requesting the chequebook and account closure. Save the file in %TOMCAT_HOME%/webapps/Application.
<html>
<head>
<title> Account Closure </title>
</head>
<body>
<%
String userName = (String)session.getAttribute("UserName");
java.util.Date d = new java.util.Date();
try
{
Class.forName("sun.jdbc.odbc.JdbcOdbcDriver");
java.sql.Connection connection =
java.sql.DriverManager.getConnection("jdbc:odbc:userdb");
java.sql.Statement statement =
connection.createStatement();
String query_car = "update userdetails set ClosureStatus
ChqStatus= 'Requested for Account Closure on" +
d.toString() + "' where UserName = '" + userName + "'" ;
statement.execute(query_car);
}
catch(Exception e)
{
e.printStackTrace();
}
%>
<h1 align='center'>Your Request is Recorded on <%=d.toString()%>...</h1>
<br><br>
<a href="redirecterServlet?action=home">Marko Home</a><br>
<a href="redirecterServlet?action=Withdrawal">Withdrawal<a><br>
<a href="redirecterServlet?action=deposit">Deposit<a><br>
<a href="redirecterServlet?action=chq">Request for cheque book</a><br>
</body>
</html>
Enter the code in Notepad and save the file as acclosure.jsp in %TOMCAT_HOME%/webapps/ Application.
package MARKO;
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
public class MainServlet extends HttpServlet
{
public void doPost(HttpServletRequest request,
HttpServletResponse response) throws ServletException,
IOException {doGet(request,response);
}
public void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
PrintWriter out = response.getWriter();
response.setContentType("text/html");
String action;
HttpSession ses = request.getSession(true);
action = request.getParameter("action");
if (action == null)
{
return;
}
else if (action.equals("home"))
{
RequestDispatcher dis =
request.getRequestDispatcher("/home.jsp");
dis.include(request, response);
}
else if (action.equals("chq"))
{
RequestDispatcher dis =
request.getRequestDispatcher("/chq.jsp");
dis.include(request, response);
}
else if (action.equals("acclosure"))
{
RequestDispatcher dis =
request.getRequestDispatcher("/acclosure.jsp");
dis.include(request, response);
}
else if (action.equals("Withdrawal"))
{
RequestDispatcher dis =
request.getRequestDispatcher("/Withdrawal.jsp");
//Withdrawal.jsp is created in LG
dis.include(request, response);
}
else if (action.equals("deposit"))
{
RequestDispatcher dis =
request.getRequestDispatcher("/deposit.jsp");
//deposit.jsp is created in LG
dis.include(request, response);
}
else
{
out.println("Error in Accessing the Site");
}
out.close();
}
}
Update the MainServlet.java page, to redirect the request to the new chequebook page. Save the file in %TOMCAT_HOME%/webapps/Application.
The output of the program is as shown in the Figure 15.1.
The output of the user request for the new chequebook is shown in Figure 15.2.
The output of the user request for the account closure is shown in Figure 15.3.
0 nhận xét:
Post a Comment