Question

In: Computer Science

Part I – Build a simple Servlet called MyServlet using NetBeans. Add this Servlet to you...

Part I Build a simple Servlet called MyServlet using NetBeans. Add this Servlet to you “ChattBank” Project. This MyServlet will display a message like “Go Braves” in a simple <h1> tag. Run this servlet from a Browser window by typing in the servlet name in the URL line.

(ie. http://localhost:8080/ChattBank/MyServlet). Make sure that your Server is up and running before you test this Servlet. The best way to do this is just Run your “ChattBank” Project once before you test the Servlet. Running the Project will start the Server.

Part IINext, build a simple Servlet called LoginServlet in your “ChattBank” Project. Now make it so that when the Customer logs in, the LoginServlet will get called and will validate the user id and password.

  1. At first, just make sure that the Servlet gets called correctly. So just print a simple message like “LoginServlet Running…”.
  2. Remember, to call the LoginServlet, you will need to modify the FORM tag in the “Login.html” file:

<form action=”http://localhost:8080/ChattBank/LoginServlet”      method=”post”>

  1. Test it out. When you click the Login Button on the LoginForm, you should see “LoginServlet Running….”

Part IIINow, modify the LoginServlet.

  1. Make it so that when the Servlet gets called, it reads the id and password from the Login Form.

Use :    request.getParameter() to get these items. At first just read in these 2 strings and display them to the Server Log.

2.) If the id = “admin” and the Password = “123”, return an HTML page     that says “Valid Login”.

3.) If not return an HTML page that says “InValid Login”. Use out.println() to send these HTML messages.

     4.) Test out your WebApp.            

Part IVLastly, modify the LoginServlet. This time we are going to go to the database to verify the user login. First look at the ChattBank database. There is a Customers table. In this table there is a UserID and a Passwd. Write the database code, in your LoginServlet to let anyone of these customers login, using their own ids and passwords.    

Solutions

Expert Solution

As per the given details the program should be as follows :

1. index.html

<html>

    <head>

        <title>Chatt Bank</title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>

        <div>Welcome to Chatt Bank</div>

    </body>

</html>

2. Login.html

<html>

    <head>

        <title>Chatt Bank | Login</title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>

        <div style="align-content: center">

            <form action="LoginServlet" method="post">

                Id: <input type="text" name="id" id="id" value="" />

                <br/><br/>

                Password: <input type="password" name="password" id="password" />

               <br/><br/>

               <input type="submit" value="Login" name="Login" />

            </form>

        </div>

    </body>

</html>

3. welcome.html

<html>

    <head>

        <title>Chatt Bank</title>

        <meta charset="UTF-8">

        <meta name="viewport" content="width=device-width, initial-scale=1.0">

    </head>

    <body>

        <div>Welcome to Chatt Bank</div>

    </body>

</html>

4. web.xml

<?xml version="1.0" encoding="UTF-8"?>

<web-app version="3.1" xmlns="http://xmlns.jcp.org/xml/ns/javaee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd">

    <servlet>

        <servlet-name>MyServlet</servlet-name>

        <servlet-class>MyServlet</servlet-class>

    </servlet>

    <servlet>

        <servlet-name>LoginServlet</servlet-name>

        <servlet-class>LoginServlet</servlet-class>

    </servlet>

    <servlet-mapping>

        <servlet-name>MyServlet</servlet-name>

        <url-pattern>/MyServlet</url-pattern>

    </servlet-mapping>

    <servlet-mapping>

        <servlet-name>LoginServlet</servlet-name>

        <url-pattern>/LoginServlet</url-pattern>

    </servlet-mapping>

    <session-config>

        <session-timeout>

            30

        </session-timeout>

    </session-config>

    <welcome-file-list>

        <welcome-file>index.html</welcome-file>

    </welcome-file-list>

</web-app>

5. MyServlet.java

/*

* To change this license header, choose License Headers in Project Properties.

* To change this template file, choose Tools | Templates

* and open the template in the editor.

*/

import java.io.IOException;

import java.io.PrintWriter;

import javax.servlet.ServletException;

import javax.servlet.http.HttpServlet;

import javax.servlet.http.HttpServletRequest;

import javax.servlet.http.HttpServletResponse;

public class MyServlet extends HttpServlet {

    /**

     * Processes requests for both HTTP <code>GET</code> and <code>POST</code>

     * methods.

     *

     * @param request servlet request

     * @param response servlet response

     * @throws ServletException if a servlet-specific error occurs

     * @throws IOException if an I/O error occurs

     */

    protected void processRequest(HttpServletRequest request, HttpServletResponse response)

            throws ServletException, IOException {

        response.setContentType("text/html;charset=UTF-8");

        try (PrintWriter out = response.getWriter()) {

            /* TODO output your page here. You may use following sample code. */

            out.println("<!DOCTYPE html>");

            out.println("<html>");

            out.println("<head>");

            out.println("<title>Chatt Bank</title>");         

            out.println("</head>");

            out.println("<body>");

            out.println("<h1>Go Braves </h1>");

            out.println("<a href=\"Login.html\">Go for login</a>");

            out.println("</body>");

            out.println("</html>");

        }

    }

    // <editor-fold defaultstate="collapsed" desc="HttpServlet methods. Click on the + sign on the left to edit the code.">

    /**

     * Handles the HTTP <code>GET</code> method.

     *

     * @param request servlet reques

HOPE THIS MAY HELP YOU---

THANK YOU ……. PLEASE LIKE,IT WILL INCREASE MY SCORE,

HOPE YOU WILL ENCOURAGE ME…..


Related Solutions

I need to build a simple model of a coffee shop using Arena simulation
I need to build a simple model of a coffee shop using Arena simulation
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In...
Part 1 – Classes and objects Create a new Java project called usernamePart1 in NetBeans. In my case the project would be called rghanbarPart1. Select the option to create a main method. Create a new class called Vehicle. In the Vehicle class write the code for: • Instance variables that store the vehicle’s make, model, colour, and fuel type • A default constructor, and a second constructor that initialises all the instance variables • Accessor (getters) and mutator (setters) methods...
I am using NetBeans IDE Java for coding. I would like the code to be commented...
I am using NetBeans IDE Java for coding. I would like the code to be commented for a better understanding. 1. Implement a class Robot that simulates a robot wandering on an infinite plane. The robot is located at a point with integer coordinates and faces north, east, south, or west. Supply methods: public void turnLeft() public void turnRight() public void move() public Point getLocation() public String getDirection() The turnLeft and turnRight methods change the direction but not the location....
Describe, using words and drawings, how you would build a circuit to add floating point numbers.
Describe, using words and drawings, how you would build a circuit to add floating point numbers.
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace...
C++ Simple Programming Assignment you need to build off of the code below: #include using namespace std; // class definition class Fraction {         // two data members         // one representing numerator         int numerator;         // other, representing denominator         int denominator;         public:                 void set (int numerator, int denominator);                 Fraction addedTo (Fraction f);                 Fraction subtract (Fraction f);                 Fraction multipliedBy (Fraction f);                 Fraction dividedBy (Fraction f);                 bool isEqualTo (Fraction f);                 void print (); }; void Fraction :: set (int numerator, int denominator) {         this...
Make this simple C++ code add data into a file called "Medical Database" preferably an excel...
Make this simple C++ code add data into a file called "Medical Database" preferably an excel file. Also ask the patient for blood type and if they're donors. Anytime I run this code, it should add new data into the same Medical Database file. Use comments to explain what each line of code is doing. (including the one I have written) Side note: I'm trying to explain how data mining works in the medical field and the medical database file...
Design a simple program, using pseudocode, to implement the recursive formula you found in part (a)...
Design a simple program, using pseudocode, to implement the recursive formula you found in part (a) to compute numbers in the Fibonacci sequence. Describe in detail how your program implements the recursive formula. You may find it useful to discuss how it through a concrete example such as F(8) = 21.
For this assignment you will implement a dynamic array. You are to build a class called...
For this assignment you will implement a dynamic array. You are to build a class called MyDynamicArray. Your dynamic array class should manage the storage of an array that can grow and shrink. The public methods of your class should be the following: MyDynamicArray(); Default Constructor. The array should be of size 2. MyDynamicArray(int s); For this constructor the array should be of size s. ~MyDynamicArray(); Destructor for the class. int& operator[](int i); Traditional [] operator. Should print a message...
Using JAVA and NETBEANS Assignment Content For this assignment, you will develop "starter" code. After you...
Using JAVA and NETBEANS Assignment Content For this assignment, you will develop "starter" code. After you finish, your code should access an existing text file that you have created, create an input stream, read the contents of the text file, sort and store the contents of the text file into an ArrayList, then write the sorted contents via an output stream to a separate output text file. Copy and paste the following Java™ code into a JAVA source file in...
Assignment 1: Build a simple class called DBTester.java. This class should have only one method, main...
Assignment 1: Build a simple class called DBTester.java. This class should have only one method, main method. In the main method you should read in all of the rows of data from the Instructors Table in the Registration Database, then print out this data. Follow the steps outlined in class. Remember to use try-catch blocks for all database access code. The example in the book does not use Try-catch blocks, but you should
ADVERTISEMENT
ADVERTISEMENT
ADVERTISEMENT