Friday 30 June 2017

Jsp-Servlet App-1

Banking Application

I created complete bank app which perform as many bank operation as real world bank can do. So this application is based on Jsp-Servlet technology which integrates with the mysql database server. This application perform the following things.



1.Register New User
2.Validate new user whether its already exist in database or not.
3.Save credentials of new user to database
4.Then register page redirect to login page if registration done successfully.
5.Login takes username and password if both [parameter are validates then it will move to the bank home page otherwise error message will show.
6.Homepage has following pages
·         Home
·         Passbook Details
·         Save passbook as a excel file.
·         Transaction Page
o   Withdraw Money
o   Diposite Money
·         Logout Page
7.Send Mail to registered mail id about registration successful.

To perform and run this application we required this software and libraries
      1.Softwares
     o        Eclipse IDE
     o     Mysql Server
     o   Tomcat Server

2.Libraries
   o   Activation.jar
   o   Mail.jar
   o   mysql-connector-jav5.1.35-bin.jar
   o   Servlet-api.jar

Now install all these softwares and libraries and and move on to the eclipse workspace
1.create new dynamic web application
2.inside WEB-INF lib folder is there put this all libraries and do add to build path operation on all the libraries.




Lets see in coding area .

1.index.jsp page :
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!doctype html>
<html lang="en">

<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<style>
body {
background-image:
url("http://wallpaper-gallery.net/images/website-wallpaper/website-wallpaper-11.jpg");
background-color: #cccccc;
text-align: center;
}

button {
margin: 100px;
display: inline;
height: 50px;
width: 200px;
}

header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
}
</style>

<meta charset="utf-8">
<meta name="Homepage" content="Starting page for the survey website ">

<title>Bank App</title>
</head>

<body>
<header>
<h1>Welcome To ABC Bank</h1>
</header>
<h3>
<marquee style="color: aliceblue">Now pay your bills using
Bharat Bill Payment services on ABC Mobile Banking & Internet Banking</marquee>
</h3>
<div>

<a href="Login"><button class="btn btn-secondary btn-lg">Login</button></a>


<a href="Register"><button class="btn btn-secondary btn-lg">Register</button></a>


</div>
</body>

</html>
2.login.jsp  page:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bank App</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<style>
header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
}

body {
background-image:
url("http://wallpaper-gallery.net/images/website-wallpaper/website-wallpaper-11.jpg");
background-color: #cccccc;
text-align: center;
}

.imgcontainer {
text-align: center;
margin: 24px 0 12px 0;
}

img.avatar {
width: 40%;
border-radius: 50%;
}

.container {
padding: 16px;
}
</style>
</head>

<body>
<header>
<h1>Login Module</h1>
</header>
<br>
<br>
<br>
<div class="row">
<div class="col-sm-offset-3  col-sm-6">
<div role="tabpanel" class="tab-pane active" id="home">
<form action="Login" method="post">
<div class="imgcontainer">
<img src="https://img.washingtonpost.com/wp-apps/imrs.php?src=https://img.washingtonpost.com/news/soloish/wp-content/uploads/sites/46/2016/08/AsianDating2.jpg&w=1484"alt="Avatar" class="avatar">
</div>
<div class="form-group">
<label style="color: white;"> User name </label> <input
type="text" class="form-control" name="username"
placeholder="Enter Your username" required>
</div>
<div class="form-group">
<label style="color: white;">Password</label> <inputtype="password" class="form-control" name="password" placeholder="Enter Your Password" required>
</div>
<div>
<span class="psw" style="color: white;"><a href="#" style="color: white;">Forgot password?</a></span>
</div><br><button type="submit" class="btn btn-primary btn-lg">Submit</button>

</form></div>
</div>
</div>
</div>
</body>

</html>

2.Login.java  servlet:
import java.io.IOException;
import java.io.PrintWriter;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.RequestDispatcher;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

import com.mysql.jdbc.Connection;


/**
* Servlet implementation class Login
*/
@WebServlet("/Login")
public class Login extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public Login() {
super();
System.out.println("inside login controller");
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
*      response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
request.getRequestDispatcher("login.jsp").forward(request, response);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
*      response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
PrintWriter writer = response.getWriter();
String username, password;
username = request.getParameter("username");
password = request.getParameter("password");
Connection connection = (Connection) RegisterCon.connectDb();
String sql = "select Cid,UserName,Password,Balance,Email,Image from master where Username='" + username
+ "' and Password='" + password + "'";
try {
PreparedStatement statement = connection.prepareStatement(sql);
ResultSet resultSet = statement.executeQuery();
if (resultSet.next()) {
HttpSession session = request.getSession();
session.setAttribute("cid", resultSet.getString(1));
session.setAttribute("username", username);
session.setAttribute("balance", resultSet.getDouble(4));
session.setAttribute("Email", resultSet.getString(5));
session.setAttribute("pic", resultSet.getBinaryStream(6));
response.sendRedirect("Home");
} else {
JOptionPane optionPane = new JOptionPane("Invalid Login", JOptionPane.WARNING_MESSAGE);
JDialog dialog = optionPane.createDialog("Warning!");
dialog.setAlwaysOnTop(true); // to show top of all other //
// application
dialog.setVisible(true);
request.getRequestDispatcher("login.jsp").forward(request, response);
}
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}

}

}


3.register.jsp :

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html lang="en">

<head>

<meta charset="utf-8">
<meta http-equiv="X-UA-Compatible" content="IE=edge">
<meta name="viewport" content="width=device-width, initial-scale=1">
<title>Bank App</title>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<style>
header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
}

body {
background-image:
url("http://wallpaper-gallery.net/images/website-wallpaper/website-wallpaper-11.jpg");
background-color: #cccccc;
text-align: center;
}

.imgcontainer {
text-align: center;
margin: 05px 0 12px 0;
}

img.avatar {
width: 30%;
border-radius: 50%;
}

.container {
padding: 10px;
}
</style>
<script type="text/javascript">
function Validate() {
var password = document.getElementById("pwd").value;
var confirmPassword = document.getElementById("repwd").value;
var balance = document.getElementById("obalance").value;
if (password != confirmPassword) {
alert("Both Passwords Field Should Be Same");
return false;
} else if (balance < 1000) {
alert("opening balance should be greater then 1000 Rs");
return false;
} else {
return true;
}

}
</script>
<script type="text/javascript">
function loadXMLDoc() {
var xmlhttp;
var k = document.getElementById("username").value;
var urls = "checkusername.jsp?user=" + k;

if (window.XMLHttpRequest) {
xmlhttp = new XMLHttpRequest();
} else {
xmlhttp = new ActiveXObject("Microsoft.XMLHTTP");
}
xmlhttp.onreadystatechange = function() {
if (xmlhttp.readyState == 4) {
document.getElementById("err").innerHTML = xmlhttp.responseText;
}
}
xmlhttp.open("GET", urls, true);
xmlhttp.send();
}
</script>
</head>

<body>
<header>
<h1>Registration Module</h1>
</header>
<br>
<br>
<br>
<div class="row">
<div class="col-sm-offset-3  col-sm-6">
<div role="tabpanel" class="tab-pane active" id="home">
<form action="Register" method="post">
<div class="imgcontainer">
<img
src="https://thumb1.shutterstock.com/display_pic_with_logo/941665/200104667/stock-vector-group-cartoon-people-eps-vector-format-200104667.jpg"
alt="Avatar" class="avatar">
</div>
<div class="form-group">
<label style="color: white;">User Name </label> <input type="text"
class="form-control" name="username" id="username"
placeholder="Enter Your Username" required onkeyup="loadXMLDoc()"><span
id="err"> </span>
<div id="status"></div>
<script type="text/javascript" src=""></script>
</div>
<div class="form-group">
<label style="color: white;">Opening Balance</label> <input
type="number" class="form-control" name="openingbalance"
placeholder="Enter Your Opening Amount" required id="obalance">
</div>
<div class="form-group">
<label style="color: white;">Password</label> <input
type="password" class="form-control" name="password"
placeholder="Enter Your Password" required id="pwd">
</div>
<div class="form-group">
<label style="color: white;">Re-Enter Your Password</label> <input
type="password" class="form-control" name="repassword"
placeholder="Enter Your Password Again" required id="repwd">
</div>
<div class="form-group">
<label style="color: white;">Email Address</label> <input
type="email" class="form-control" name="email"
placeholder="Enter Your Email Address" required>
</div>
<div class="form-group">
<label style="color: white;">Upload Image </label> <input
type="file" class="form-control" name="pic" accept="image/*"
placeholder="Enter Your Email Address" required>
</div>
<br>
<button type="submit" class="btn btn-primary btn-lg" id="submitbtn"
onclick="return Validate()">Submit</button>
</form>
</div>

</div>
</div>
</div>
</body>

</html>

4.Register.java  servlet:

import java.io.IOException;
import java.io.PrintWriter;
import java.lang.ref.ReferenceQueue;
import java.nio.channels.ShutdownChannelGroupException;
import java.sql.DriverManager;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;
import java.sql.Statement;

import javax.servlet.ServletContext;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

import com.mysql.jdbc.Connection;

//import com.techlabs.service.EmailService;
import com.techlabs.service.ErrorService;
import com.techlabs.service.Mailer;

/**
* Servlet implementation class Register
*/
@WebServlet("/Register")
public class Register extends HttpServlet {
private static final long serialVersionUID = 1L;
private String host;
private String port;
private String user;
private String pass;

public void init() {
// reads SMTP server setting from web.xml file
ServletContext context = getServletContext();
host = context.getInitParameter("host");
port = context.getInitParameter("port");
user = context.getInitParameter("user");
pass = context.getInitParameter("pass");
}

/**
* @see HttpServlet#HttpServlet()
*/
public Register() {
super();
System.out.println("insite register controller");
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
*      response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

request.getRequestDispatcher("register.jsp").forward(request, response);
}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
*      response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {


// ErrorService errorService = null;
String resultMsg = "";
String subject = "Bank App";
String content = "Sent Successfully";
PrintWriter out = response.getWriter();
response.setContentType("text/html");
String username, password, balance, email, pic;
username = request.getParameter("username").toString();
balance = request.getParameter("openingbalance").toString();
password = request.getParameter("password").toString();
email = request.getParameter("email").toString();
pic = request.getParameter("pic").toString();

Connection connection = (Connection) RegisterCon.connectDb();
try {
String sql = "insert into master (UserName,Password,Balance,Email,Image) values ('" + username + "','"
+ password + "','" + balance + "','" + email + "','" + pic + "')";
PreparedStatement statement = connection.prepareStatement(sql);
statement.execute();
HttpSession session =request.getSession();
session.setAttribute("balance",balance);
response.sendRedirect("Login");
// EmailService.sendEmail(host, port, user, pass, email, subject,
// content);
// resultMsg = "The e-mail was sent successfully";

out.println("Registered Successfully");
Mailer.send("bankapp96@gmail.com","bankapp1996",email,"Registration successful ","Thank u for choosing us.");
System.out.println("Done Registration");

// System.out.println("mail sent");

} catch (Exception e) {
//ErrorService errorService = null;
System.out.println(e);
JOptionPane optionPane = new JOptionPane("Username is already Taken", JOptionPane.WARNING_MESSAGE);
JDialog dialog = optionPane.createDialog("Warning!");
dialog.setAlwaysOnTop(true); // to show top of all other application
dialog.setVisible(true);
request.getRequestDispatcher("register.jsp").forward(request, response);

// resultMsg = "There were an error: " + e.getMessage();
} finally {
// request.setAttribute("Message", resultMsg);
// getServletContext().getRequestDispatcher("/Result.jsp").forward(
// request, response);
try {
connection.close();
} catch (SQLException e) {
// TODO Auto-generated catch block
e.printStackTrace();
}
}

}
}
5.checkusername.jsp  :
<%@ page import="java.io.*,java.sql.*"%>
<%@ page contentType="text/html" pageEncoding="UTF-8"%>

<%
String user = request.getParameter("user");

Class.forName("com.mysql.jdbc.Driver");
Connection conn = DriverManager
.getConnection("jdbc:mysql://localhost:3306/bank?" + "user=root&password=admin");
Statement st = conn.createStatement();
ResultSet rs = st.executeQuery("select * from master where UserName='" + user + "'"); // this is for name
if (rs.next()) {
out.println("<font color=red>");
out.println("User Name already exists...");
out.println("</font>");

} else {
out.println("<font color=green>");
out.println("UserName Available");
out.println("</font>");

}
rs.close();
st.close();
conn.close();
%>


6. home.jsp

<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!doctype html>
<html lang="en">

<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<style>
body {
background-image:
url("http://wallpaper-gallery.net/images/website-wallpaper/website-wallpaper-11.jpg");
background-color: #cccccc;
text-align: center;
}

button {
margin: 100px;
display: inline;
height: 50px;
width: 200px;
}

header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
}
</style>

<meta charset="utf-8">
<meta name="Homepage" content="Starting page for the survey website ">

<title>Bank App</title>
<style>
nav {
float: left;
max-width: 200px;
margin: 20;
padding: 10;
}

nav ul {
list-style-type: none;
padding: 0;
}

nav ul a {
text-decoration: none;
}

ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: gray;
}

li {
float: left;
}

li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

li a:hover {
background-color: #111;
}
</style>
</head>

<body>

<%
if (session.getAttribute("username") == null) {
response.sendRedirect("/bank-app");
}
String uname = (String) session.getAttribute("username");
%>
<header>
<h1>Welcome To ABC Bank</h1>
<h3>
<marquee style="color: aliceblue">Now pay your bills using
Bharat Bill Payment services on ABC Mobile Banking & Internet
Banking</marquee>
</h3>
</header>
<nav>
<ul class="nav nav-pills">
<li><a href="/bank-app/Home"><span
class="glyphicon glyphicon-user">Home</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Transaction"><span
class="glyphicon glyphicon-user">Transaction</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Passbook"><span
class="glyphicon glyphicon-list">Passbook Details</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Profile"><span
class="glyphicon glyphicon-list">My Profile</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Logout"><span
class="glyphicon glyphicon-list">Logout</a></li>


</ul>
</nav>

<article>
<h1 style="color: aqua;">
Hello ,<%=uname%></h1><br><br>
<p style="color: white;"> <h3 style="color: aqua;"> Announcements</h3>
<h4 style="color: white;" align="justify">Important Information for ABC Bank Magstripe
Debit Cardholders Upgradation of Magstripe Debit Cards to EMV Chip
Cards for enhanced security and towards compliance of RBI guidelines.
Esteemed customers may please note that Magstripe Debit Cards blocked
by them will remain blocked permanently. </p>
</h4>
</article>
</body>

</html>

7.Home.java servlet :
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;

/**
* Servlet implementation class Home
*/
@WebServlet("/Home")
public class Home extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public Home() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.getRequestDispatcher("home.jsp").forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
// TODO Auto-generated method stub
doGet(request, response);
}

}

8. transactio.jsp Page:
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!doctype html>
<html lang="en">


<head>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<style>
body {
background-image:
url("http://wallpaper-gallery.net/images/website-wallpaper/website-wallpaper-11.jpg");
background-color: #cccccc;
text-align: center;
}

button {
margin: 100px;
display: inline;
height: 50px;
width: 200px;
}

header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
}
</style>

<meta charset="utf-8">
<meta name="Homepage" content="Starting page for the survey website ">

<title>Bank App</title>
<style>
nav {
float: left;
max-width: 200px;
margin: 20;
padding: 10;
}

nav ul {
list-style-type: none;
padding: 0;
}

nav ul a {
text-decoration: none;
}

ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: gray;
}

li {
float: left;
}

li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

li a:hover {
background-color: #111;
}
</style>
<script type="text/javascript">
function validate1() {
var withdraw = document.getElementById("withdraw").value;
if (withdraw < 1000) {
alert("Amount should be greater then 1000 Rs");
return false;
} else {
return true;
}
}
function validate2() {
var diposite = document.getElementById("deposite").value;
if (withdraw < 1) {
alert("Amount should be greater then 1000 Rs");
return false;
} else {
return true;
}

}
</script>
</head>

<body>
<%
if (session.getAttribute("username") == null) {
response.sendRedirect("/bank-app");
}
double balance = (double) session.getAttribute("balance");
String cid = (String) session.getAttribute("cid");
%>
<header>
<h1>Welcome To Transaction</h1>
<h3>
<marquee style="color: aliceblue">Now pay your bills using
Bharat Bill Payment services on ABC Mobile Banking & Internet
Banking</marquee>
</h3>
</header>
<nav>
<ul class="nav nav-pills">
<li><a href="/bank-app/Home"><span
class="glyphicon glyphicon-user">Home</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Transaction"><span
class="glyphicon glyphicon-user">Transaction</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Passbook"><span
class="glyphicon glyphicon-list">Passbook Details</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Profile"><span
class="glyphicon glyphicon-list">My Profile</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Logout"><span
class="glyphicon glyphicon-list">Logout</a></li>


</ul>
</nav>

<article>
<h2 style="color: aqua;">
Total Balance Is :<%=balance%></h2>

<script language="Javascript">
function hideA(x) {
if (x.checked) {
document.getElementById("A").style.visibility = "hidden";
document.getElementById("B").style.visibility = "visible";
}
}

function hideB(x) {
if (x.checked) {
document.getElementById("B").style.visibility = "hidden";
document.getElementById("A").style.visibility = "visible";
}
}
</script>
<br>

<h3 style="color: white;">
<label>Select Your Operation :</label>
</h3>
<input type="radio" onchange="hideB(this)" name="aorb" id="wid"
checked><label style="color: aqua;">Withdraw&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp&nbsp</label> <input
type="radio" onchange="hideA(this)" id="pid" name="aorb"><label
style="color: aqua;">Diposite</label>
<div style="text-align: center;" id="A">
<form action="Withdraw" method="post">
<label style="color: white;">Amount To Wirhdraw : </label><input
type="number" id="withdraw" name="wmoney" required>
<button style="color: black;" onclick="validate1()">Proceed</button>
</form>
</div>
<div id="B" style="visibility: hidden""border:1pxsolidred; display:inline-block;">
<form action="Diposite" method="post">
<label style="color: white;">Amount To Diposite : </label><input
type="number" id="diposite" name="dmoney" required>
<button style="color: black;" onclick="validate2()">Proceed</button>
</form>
</div>
</div>
</article>
</body>

</html>

9.Transaction.java  Servlet  :

import java.io.IOException;
import java.io.PrintWriter;
import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.sql.SQLException;

import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
import javax.swing.JDialog;
import javax.swing.JOptionPane;

/**
* Servlet implementation class Transaction
*/
@WebServlet("/Transaction")
public class Transaction extends HttpServlet {
private static final long serialVersionUID = 1L;

/**
* @see HttpServlet#HttpServlet()
*/
public Transaction() {
super();
// TODO Auto-generated constructor stub
}

/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
*      response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {

request.getRequestDispatcher("transaction.jsp").forward(request, response);

}

/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
*      response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
}

}


10.  passbook.jsp Page :

<%@page import="java.sql.SQLException"%>
<%@page import="java.sql.Timestamp"%>
<%@page import="java.sql.ResultSet"%>
<%@page import="java.sql.PreparedStatement"%>
<%@page import="com.techlabs.connection.RegisterCon"%>
<%@page import="java.sql.Connection"%>
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!doctype html>
<html lang="en">

<head>
<script type="text/javascript">
function fnExcelReport() {
var tab_text = "<table border='2px'><tr bgcolor='#87AFC6'>";
var textRange;
var j = 0;
tab = document.getElementById('table'); // id of table

for (j = 0; j < tab.rows.length; j++) {
tab_text = tab_text + tab.rows[j].innerHTML + "</tr>";
//tab_text=tab_text+"</tr>";
}

tab_text = tab_text + "</table>";
tab_text = tab_text.replace(/<A[^>]*>|<\/A>/g, ""); //remove if u want links in your table
tab_text = tab_text.replace(/<img[^>]*>/gi, ""); // remove if u want images in your table
tab_text = tab_text.replace(/<input[^>]*>|<\/input>/gi, ""); // reomves input params

var ua = window.navigator.userAgent;
var msie = ua.indexOf("MSIE ");
if (msie > 0 || !!navigator.userAgent.match(/Trident.*rv\:11\./)) // If Internet Explorer
{
txtArea1.document.open("txt/html", "replace");
txtArea1.document.write(tab_text);
txtArea1.document.close();
txtArea1.focus();
sa = txtArea1.document.execCommand("SaveAs", true,
"Say Thanks to Sumit.xls");
} else
//other browser not tested on IE 11
sa = window.open('data:application/vnd.ms-excel,'
+ encodeURIComponent(tab_text));

return (sa);
}
</script>
<!-- Latest compiled and minified CSS -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap.min.css"
integrity="sha384-BVYiiSIFeK1dGmJRAkycuHAHRg32OmUcww7on3RYdg4Va+PmSTsz/K68vbdEjh4u"
crossorigin="anonymous">

<!-- Optional theme -->
<link rel="stylesheet"
href="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/css/bootstrap-theme.min.css"
integrity="sha384-rHyoN1iRsVXV4nD0JutlnGaslCJuC7uwjduW9SVrLvRYooPp2bWYgmgJQIXwl/Sp"
crossorigin="anonymous">
<script
src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.4/jquery.min.js"></script>
<script src="js/bootstrap.min.js"></script>
<!-- Latest compiled and minified JavaScript -->
<script
src="https://maxcdn.bootstrapcdn.com/bootstrap/3.3.7/js/bootstrap.min.js"
integrity="sha384-Tc5IQib027qvyjSMfHjOMaLkfuWVxZxUPnCJA7l2mCWNIpG9mGCD8wGNIcPD7Txa"
crossorigin="anonymous"></script>
<style>
body {
background-image:
url("http://wallpaper-gallery.net/images/website-wallpaper/website-wallpaper-11.jpg");
background-color: #cccccc;
text-align: center;
}

button {
margin: 100px;
display: inline;
height: 50px;
width: 200px;
}

header, footer {
padding: 1em;
color: white;
background-color: black;
clear: left;
text-align: center;
}
</style>

<meta charset="utf-8">
<meta name="Homepage" content="Starting page for the survey website ">

<title>Bank App</title>
<style>
nav {
float: left;
max-width: 200px;
margin: 20;
padding: 10;
}

nav ul {
list-style-type: none;
padding: 0;
}

nav ul a {
text-decoration: none;
}

ul {
list-style-type: none;
margin: 0;
padding: 0;
overflow: hidden;
background-color: gray;
}

li {
float: left;
}

li a {
display: block;
color: white;
text-align: center;
padding: 14px 16px;
text-decoration: none;
}

li a:hover {
background-color: #111;
}
</style>
</head>

<body>
<%
if (session.getAttribute("username") == null) {
response.sendRedirect("/bank-app");
}
String cid = (String) session.getAttribute("cid");
String name = (String) session.getAttribute("username");
%>
<header>
<h1>Welcome To Passbook</h1>
<h3>
<marquee style="color: aliceblue">Now pay your bills using
Bharat Bill Payment services on ABC Mobile Banking & Internet
Banking</marquee>
</h3>
</header>
<nav>
<ul class="nav nav-pills">
<li><a href="/bank-app/Home"><span
class="glyphicon glyphicon-user">Home</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Transaction"><span
class="glyphicon glyphicon-user">Transaction</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Passbook"><span
class="glyphicon glyphicon-list">Passbook Details</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Profile"><span
class="glyphicon glyphicon-list">My Profile</a></li>
<br>
<br>
<br>
<li><a href="/bank-app/Logout"><span
class="glyphicon glyphicon-list">Logout</a></li>


</ul>
</nav>
<h1 style="color: white;">Transaction Details</h1>
<h2 style="color: white;">
Customer Id :
<%=cid%></h1>
<h2 style="color: white;">
Customer Name :
<%=name%></h1>
<br> <br> <br> <br>
<div class="container">
<br> <br> <br> <br>
<table class="table table-bordered" style="color: white;" id="table">
<thead>
<tr>
<th>Transaction Id</th>
<th>Customer Id</th>
<th>Transaction Type</th>
<th>Amount</th>
<th>Date & Time</th>
</tr>
</thead>
<%
try {
cid = (String) session.getAttribute("cid");

Connection connection = (Connection) RegisterCon.connectDb();
PreparedStatement stmt = connection.prepareStatement("SELECT * FROM transaction WHERE Cid = ?");
stmt.setString(1, cid);
ResultSet result = stmt.executeQuery();
while (result.next()) {
%>
<tbody>
<tr>
<td><%=result.getString(1)%></td>
<td><%=result.getString(2)%></td>
<td><%=result.getString(3)%></td>
<td><%=result.getDouble(4)%></td>
<td><%=result.getString(5)%></td>
</tr>
</tbody>
<%
}
%>
</table>
<%
}

catch (SQLException ex) {
// handle any errors
System.out.println("SQLException: " + ex.getMessage());
System.out.println("SQLState: " + ex.getSQLState());
System.out.println("VendorError: " + ex.getErrorCode());
}
%>
</div>
<br>
<div class="container" align="center">
<button id="btnExport" class="btn btn-primary"
onclick="fnExcelReport();">
<span class="glyphicon glyphicon-download-alt"></span>&nbsp Export
</button>
</form>
</div>
</body>


No comments:

Post a Comment

Spring-App

Application In Spring Spring Framework is an open source Java Platform that provides comprehensive infrastructure support for developi...