Question

I need help creating a netbeans application and linking database with steps Part II – Next,...

I need help creating a netbeans application and linking database with steps

Part IINext, build a simple Servlet called LoginServlet in your “Bank” 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/Bank/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, create a new LoginServletDB. This time we are going to go to the database to verify the user login. First look at the Bank database. There is a Customers table. In this table there is a UserID and a Passwd. (SHOW STEPS OF CONNECTING DATABASE (.accdb, .mdb) files to NETBEANS IDE 8.2

  1. Write the database code, in your LoginServlet to let anyone of these customers login, using their own ids and passwords.(Hint: You will need to add all 6 database steps[Load Driver, get connection….] to your LoginServletDB. Then get the password from the database and compare it to the one you read from the HTML file.
  2. Remember, to call the LoginServletDB, you will need to modify the FORM tag in the “Login.html” file:

<form action=”http://localhost:8080/Bank/LoginServletDB”

0 0
Add a comment Improve this question Transcribed image text
Answer #1

Login.html

<html>
<head>
<title>Bank login Page</title>
</head>
<body>
<form method="post" action="http://localhost:8080/Bank/LoginServlet.java">
User ID:<input type="text" name="userid" /><br/>
Password:<input type="password" name="pass" /><br/>
<input type="submit" value="login" />
</form>
</body>
</html>

LoginServlet.java validating without using database

import java.io.*;
import javax.servlet.*;
import javax.servlet.http.*;

public class Login extends HttpServlet {

protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException { //for exception handling
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
  
String UserId = request.getParameter("userid"); //getting the parameters userId
String Passwrd = request.getParameter("pass"); //getting the parameter password   
  
if(UserId.equls("admin")&&Passwrd.equls('123')) //normal checking of values
       {
           out.println("<h2> Valid login </h2>");   
       }
else
{
out.println("<h2> invalid Login </h2>");
  
}
}
}

LoginServlet.java validation using database

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 { //for exception handling
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
  
String UserId = request.getParameter("userid"); //getting the parameters userId
String Passwrd = request.getParameter("pass"); //getting the parameter password   
  
       if(checkUser(UserId, Passwrd)) //calling checkUser function to validate user from database
{
out.println("<h2> welcome " + UserId + "</h2>"); //if validation successful print welcome username   
       }
else
{
out.println("<h2> invalid Login </h2>");
  
}
}
  
public static boolean checkUser(String userid,String pass)
{
boolean st =false;
try {
Class.forName("com.mysql.jdbc.Driver"); //loading drivers for mysql
             
           //creating connection with the database
Connection conn = DriverManager.getConnection("jdbc:mysql://localhost:3306/mydb","root","1234");
PreparedStatement state = conn.prepareStatement("select * from CustomerTab where UserID=? and Passwd=?");
state.setString(1, userid);
state.setString(2, pass);
ResultSet rs = state.executeQuery();
st = rs.next();

}
catch(Exception e) {
e.printStackTrace();
}
return st;   
}    
}

Add a comment
Know the answer?
Add Answer to:
I need help creating a netbeans application and linking database with steps Part II – Next,...
Your Answer:

Post as a guest

Your Name:

What's your source?

Earn Coins

Coins can be redeemed for fabulous gifts.

Not the answer you're looking for? Ask your own homework help question. Our experts will answer your question WITHIN MINUTES for Free.
Similar Homework Help Questions
  • 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...

  • PHP Programming with MySQL - Why do I get the following error and how do I...

    PHP Programming with MySQL - Why do I get the following error and how do I connect to my database. Looks like I might need to use mysqli instead of mysql but I dont know how to do that or what to change. I appreciate it is you fixed anything that needs to be re-written. Fatal error: Uncaught Error: Call to undefined function mysql_connect() in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php:12 Stack trace: #0 {main} thrown in /Applications/XAMPP/xamppfiles/htdocs/Week9/VerifyLogin.php on line 12 Line 12: $DBConnect =...

  • i need help with this python assignment asking for creating a simple database (client application )...

    i need help with this python assignment asking for creating a simple database (client application ) そ归乔 Assignment rh ENCS-393-2174-WW: Tset5.pdf A2.pdf textbook.pdf Department of ComputV ← → O仚 file:///C 18/comp%20348/A2.pdf 5. Print Report: This will print the contents of the database, sorted by name. Note that the sorted contents should be sent by the server back to the client and then displayed by the client app. The Print Report function is r because it is the primary way for...

  • NEED HELP with HTML with Javascript embedding for form validation project below. I have my code...

    NEED HELP with HTML with Javascript embedding for form validation project below. I have my code below but I'm stuck with validation. If anyone can fix it, I'd really appreciate. ****************************************************************************** CODE: <!DOCTYPE html> <!-- 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. --> <html> <head> <title>Nice</title> <meta charset="UTF-8"> <meta name="viewport" content="width=device-width, initial-scale=1.0"> <script> var textFromTextArea; function getWords(){ var text =...

  • I have created an HTML form. I need to connect this to a database to update...

    I have created an HTML form. I need to connect this to a database to update the phone number in the employee table HTML: <!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"> <html> <head> <meta http-equiv="Content-Type" content="text/html; charset=windows-1252"> </head> <body link="#0000EE" vlink="#551A8B" text="#000000" bgcolor="#566573" alink="#EE0000" background="../DOC/brushed-alum.png"> <form method="post" action="phonenumbers.php"> <h1>Update Employee Phone Number Form</h1> <br> <br> <h3>Enter the employee's ID number.</h3> <br> <br> Employee ID Number: <input name="EmployeeNumber" type="text"> <br> <br> <h3>Enter the new phone number</h3> Phone Number: <input name="OfficePhone" type="text">...

  • // I need help in creating and publishing a website with two pages for this assignment,...

    // I need help in creating and publishing a website with two pages for this assignment, I am new to this and need a bit of help as to what and how many HTML files I need to create, and CSS files. If anyone could send me a sample code or anything to start out with it would be appreciated ! I have attached the specifications and requirements below CPI 101 Introduction to Informatics Homework #1 Check Out My Website!...

  • IN php .... I need Help I Need to Modify this application so it uses a...

    IN php .... I need Help I Need to Modify this application so it uses a persistent session to save the last values entered by the user for 5 minutes. At the top of the file (before the DOCTYPE html line) you will need to add a section of code which checks to see if a session id exists. If it does not, the code you add (which will be similar to the example on page 359) will need to...

  • I need help for part B and C 1) Create a new project in NetBeans called...

    I need help for part B and C 1) Create a new project in NetBeans called Lab6Inheritance. Add a new Java class to the project called Person. 2) The UML class diagram for Person is as follows: Person - name: String - id: int + Person( String name, int id) + getName(): String + getido: int + display(): void 3) Add fields to Person class. 4) Add the constructor and the getters to person class. 5) Add the display() method,...

  • Posting this again because day limit has run out. Again I really need help with this....

    Posting this again because day limit has run out. Again I really need help with this. This is for my Advanced Java Programming class. The book we use is Murach's Java Servlet's and JSP 3rd Edition. The program used is NetBeans IDE 8.2. I need help modifying or adding some code. I will post the code I was told to open that needs to be modified below. Exercise 9-3     Use JSTL to add a table to the Future Value application. In...

  • Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on...

    Form Processing HTML One of the most ubiquitous uses of JavaScript is validating form data on the client side before it is submitted to the server. It is done everywhere because it is fast and it gives you a great deal of flexibility in how you handle errors insofar as the GUI is concerned. Attached is an image of some code I wrote (so Blackboard can't mess it up). Some things to notice that will help you with the lab....

ADVERTISEMENT
Free Homework Help App
Download From Google Play
Scan Your Homework
to Get Instant Free Answers
Need Online Homework Help?
Ask a Question
Get Answers For Free
Most questions answered within 3 hours.
ADVERTISEMENT
ADVERTISEMENT