Create a Java Web Project called TOBA and in it create the f
Create a Java Web Project called TOBA and in it create the following HTML pages for our application.
index.html : This will be the homepage of the application. At the very least, the homepage should have the name of the banking application and a navigation.
Login.html: This page should contain a form with the following input elements and a Login Button. This page should also have a link to a “New Customer Sign Up page”,
Username
Password
New_customer.html: This page will allow the user to register for online banking services. It should have a form with a submit button that collects the following information.
FirstName
LastName
Phone
Address
City
State
Zipcode
Success.html: This page should just display a message that the account has been successfully created.
Account_activity.html: This page will be used to display the customer account information. Just add a header for now.
Transaction.html: This page will allow a user to post a transaction. Just add a header for now.
Login_failure.html: Displays a message that the login was incorrect.
Error_404.jsp: Displays 404 error code.
Error_java.jsp: Displays a message that java has thrown an exception.
Create the following Servlets:
LoginServlet – Code the servlet to retrieve the username and password from the form we added to login.html. Have the servlet check that the username is equal to HYPERLINK \"mailto:jsmith@toba.com\" jsmith@toba.com and the password is equal to “letmein”. Make sure you use these values or I can’t test your work. If the username and password match, the servlet to forward the request to the account_activity.html page. If it is incorrect, it should forward the request to the login_failure.html page.
NewCustomerServlet – Code the servlet to retrieve the new customer form data and just redirect to the success.html page.
TransactionServlet – Just create an empty servlet for now.
Server Side Validation – Code the NewCustomerServlet to validate the user has entered in values for all the form fields. If not, assign a message variable such as “Please fill out all the form fields” and display the message on the new_customer.html page.
Web XML - Configure the web.xml to map all your servlets.
Error Handling – Add the following:
XML tags that provide error-handling for an HTTP 404 status code
XML tags that provide error-handling for all Java exceptions
Solution
Index.html
<html>
<head>
<title>Banking Application</title>
</head>
</html>
Login.html
<html>
<head>
<title>login form</title>
</head>
<body>
<form method=\"post\" action=\"login\">
UserName:<input type=\"text\" name=\"uname\" /><br/>
Password:<input type=\"text\" name=\"pass\" /><br/>
<input type=\"submit\" value=\"login\" />
</form>
<form method=”Post” action=”NewCustomer”>
<input type=”Submit” value=”New User Signup”/>
</form>
</body>
</html>
NewCustomer.html
<html>
<head>
<title>New User Registration</title>
</head>
<body>
<form method=\"post\" action=\"NewCustomer\">
First Name:<input type=\"text\" name=\"fname\" /><br/>
Last Name:<input type=\"text\" name=\"lname\" /><br/>
Phone:<input type=\"text\" name=\"phone\" /><br/>
Address:<input type=\"text\" name=\"address\" /><br/>
City:<input type=\"text\" name=\"city\" /><br/>
State:<input type=\"text\" name=\"state\" /><br/>
Zip Code:<input type=\"text\" name=\"zipcode\" /><br/>
E-Mail:<input type=\"text\" name=\"email\" /><br/>
<input type=\"submit\" value=\"Register\" />
</form>
</body>
</html>
Loginfailure.html
<html>
<head>
<title>login was incorrect</title>
</head>
</html>
Success.html
<html>
<head>
<title>Account has been added successfully </title>
</head>
</html>
Login.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Login extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(\"text/html;charset=UTF-8\");
PrintWriter out = response.getWriter();
String uname = request.getParameter(\"uname\");
String pass = request.getParameter(\"pass\");
if(Validate.checkUser(uname, pass))
{
RequestDispatcher rs = request.getRequestDispatcher(\"Welcome\");
rs.forward(request, response);
}
else
{
out.println(\"Username or Password incorrect\");
RequestDispatcher rs = request.getRequestDispatcher(\"LoginFailure.html\");
rs.include(request, response);
}
}
}
NewCustomer.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Login extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(\"text/html;charset=UTF-8\");
PrintWriter out = response.getWriter();
String fname = request.getParameter(\"fname\");
String lname = request.getParameter(\"lname\");
String phone = request.getParameter(\"phone\");
String address = request.getParameter(\"address\");
String city = request.getParameter(\"city\");
String state = request.getParameter(\"state\");
String zipcode = request.getParameter(\"zipcode\");
String email = request.getParameter(\"email\");
Class.forName(\"apache_derby_net\");
Connection con=DriverManager.getConnection(\"jdbc:derby://localhost:1527/sample\",\"app\",\"\");
Statement stmt=con.createStatement();
String query= \"insert into register values(\'\"+fname+\"\',\'\"+lname+\"\',\'\"+phone+\"\',\'\"+address+\"\',\'\"+city+\"\',\'\"+state+\"\',\'\"+zipcode+\"\',\'\"+email+\"\')\";
stmt.executeUpdate(query);
}
catch(Exception e)
{
System.out.println(e.getMessage());
}
out.println(\"New user Added\");
RequestDispatcher rs = request.getRequestDispatcher(\"Success.html\");
rs.include(request, response);
}
}
}
Validate.java
import java.sql.*;
public class Validate
{
public static boolean checkUser(String uname,String pass)
{
boolean st =false;
if(uname.compareTo(“ jsmith@toba.com”)==0 and pass.compareTo(“letmein”)==0)
st=true;
return st;
}
}
Welcome.java
import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;
import java.sql.*;
public class Welcome extends HttpServlet {
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
response.setContentType(\"text/html;charset=UTF-8\");
PrintWriter out = response.getWriter();
out.println(\"Welcome user\");
}
}
web.xml
<?xml version=\"1.0\" encoding=\"UTF-8\"?>
<web-app version=\"3.0\" xmlns=\"http://java.sun.com/xml/ns/javaee\" xmlns:xsi=\"http://www.w3.org/2001/XMLSchema-instance\" xsi:schemaLocation=\"http://java.sun.com/xml/ns/javaee http://java.sun.com/xml/ns/javaee/web-app_3_0.xsd\" >
<servlet>
<servlet-name>login</servlet-name>
<servlet-class>Login</servlet-class>
</servlet>
<servlet>
<servlet-name>Welcome</servlet-name>
<servlet-class>Welcome</servlet-class>
</servlet>
<servlet-mapping>
<servlet-name>login</servlet-name>
<url-pattern>/login</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>Welcome</servlet-name>
<url-pattern>/Welcome</url-pattern>
</servlet-mapping>
<servlet-mapping>
<servlet-name>NewCustomer</servlet-name>
<url-pattern>/NewCustomer</url-pattern>
</servlet-mapping>
</web-app>





