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...

  • 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 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,...

  • 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....

  • 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...

  • The first script is validate.sh. This is a simple form validation script that will be used...

    The first script is validate.sh. This is a simple form validation script that will be used to verify the inputs given. Normally, this would be done to validate input from a website or another program before entry into a database or other record storage. In this case, we will keep it simple and only focus on the input validation step. In particular, the script should prompt the user for four values: first name, last name, zip code, and email address....

  • Question I This question carries 20% of the marks for this assignment. You are asked to...

    Question I This question carries 20% of the marks for this assignment. You are asked to develop a set of bash shell script: Write a script that asks for the user's salary per month. If it is less or equals to 800, print a message saying that you need to get another job to increase your income, what you earn is the Minim living cost. If the user's salary is higher than 800 and below 2000, print a message telling...

  • I'm need help in the Pacific Trails section of the assignment. I posted my chapter 2...

    I'm need help in the Pacific Trails section of the assignment. I posted my chapter 2 assignment on the bottom of the picture. I'm using Notepad++. This was the previous assignment: CHAPTER 2 ASSIGMENT paste the first content to index.html file and second to yurts.html. First: (index.html contents are below) <!DOCTYPE html> <head> <title>Pacific Trails Resorts</title> </head> <style> a{    padding-right:14px; /* padding anchor tage to right 15px for nav menu */ } </style> <body> <header> <h1>Pacific Trails Resort</h1>   ...

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
ADVERTISEMENT