Here is the Java Source Code:-
import java.awt.image.*;
import java.io.*;
import java.nio.file.*;
import java.util.*;
import javax.imageio.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class Login extends HttpServlet {
@Override
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
String email, password;
email = req.getParameter("email");
password = req.getParameter("password");
if (!(email == null && password == null)) {
login(email, password, req, res);
}
}
private void login(String email, String password, HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
PrintWriter out = res.getWriter();
boolean invalid = false;
try {
File acc = new File(System.getProperty("user.home"), "\\My Documents\\Accounts\\" + email.toLowerCase());
File pas = new File(acc, "password.txt");
BufferedReader buff = new BufferedReader(new FileReader(pas));
String storedPassword = buff.readLine();
if (storedPassword == null ? password == null : storedPassword.equals(password)) {
logined(req, res, email);
} else {
invalid = true;
}
} catch (IOException e) {
invalid = true;
} finally {
if (invalid == true) {
Path uri = Paths.get("E:/NetBeans HTML/Servlets/ServletsExample/build/web/WEB-INF/Login Sign Up.html");
Zucksnet ash = new Zucksnet("Zucksnet Style.css");
out.println("<html>\n<head>");
res.setContentType("text/css");
out.println("<style>");
String style[] = Zucksnet.getStyle();
for (int i = 0; i < style.length; i++) {
out.println(style[i]);
}
out.println("</style>");
out.println("<title>Login Failed!</title>\n</head>\n<body>");
res.setContentType("text/html");
out.println("Please Check Your Email or Password!");
out.println("</body>\n</html>");
}
}
}
private void logined(HttpServletRequest req, HttpServletResponse res, String email) throws IOException {
ImageServlet imageServlet = new ImageServlet();
imageServlet.setName(email);
PrintWriter out = res.getWriter();
String pathToWeb = getServletContext().getRealPath(File.separator);
Scanner scan;
File file = new File(pathToWeb, "Zucksnet Style.css");
scan = new Scanner(file);
res.setContentType("text/html");
out.println("<html>\n<head>\n<title>\nLogin\n</title>\n<style>");
res.setContentType("text/css");
while (scan.hasNextLine()) {
out.println(scan.nextLine());
}
out.println("</style>");
file = new File(pathToWeb, "home_script.txt");
scan = new Scanner(file);
while (scan.hasNextLine()) {
out.println(scan.nextLine());
}
file = new File(pathToWeb, "head.txt");
scan = new Scanner(file);
res.setContentType("text/html");
out.println("</head>\n<body id=\"homePage\" text=\"black\">");
while (scan.hasNextLine()) {
out.println(scan.nextLine());
}
out.println("<br><br>");
file = new File(pathToWeb, "body.txt");
scan = new Scanner(file);
while (scan.hasNextLine()) {
out.println(scan.nextLine());
}
out.println("</body>\n</html>");
}
}
HTML Source Code:-
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body id="mobile" style="text-align: left; background-color: #294a8f; font-family: sans-serif; color: white;" onload="links(); buttons(); mobiles(); dob();">
<div align="left">
<form method="post" action="http://localhost:8084/ServletsExample/build/web/WEB-INF/classes/Login">
<table>
<tbody>
<tr>
<td><label for="email">E-mail</label></td><tr>
<td> <input name="email" type="email" id="email" autocomplete="off" placeholder="E-mail" autofocus style="font-kerning: auto; border-color: #294a8f; font-weight: bolder; background-color: #3B5998; color: white; text-spacing: none" size="32"/><tr>
<td><label for="password">Password</label></td><tr>
<td> <input name="password" type="password" id="password" autocomplete="off" placeholder="Password" style="font-kerning: auto; border-color: #294a8f; font-weight: bolder; background-color: #3B5998; color: white" size="32"/><tr>
<td><label for="remainLoggedIn" title="Remain Logged In on this Computer. Not recomonthended if using an shared Computer">
<input type="checkbox" id="remainLoggedIn" title="Remain Logged In on this Computer. Not recomonthended if using an shared Computer" style="appearance: checkbox; background-color: #3B5998; color: white"/>Remember me?</label><tr>
<td><button title="Login to your account" type="submit" style="background-color: #294a8f; border-color: #2C4272; appearance: push-button; color: white;">Login</button>
</tbody>
</table>
</form>
</div>
</body>
</html>
import java.awt.image.*;
import java.io.*;
import java.nio.file.*;
import java.util.*;
import javax.imageio.*;
import javax.servlet.ServletException;
import javax.servlet.http.*;
public class Login extends HttpServlet {
@Override
public void service(HttpServletRequest req, HttpServletResponse res) throws IOException, ServletException {
String email, password;
email = req.getParameter("email");
password = req.getParameter("password");
if (!(email == null && password == null)) {
login(email, password, req, res);
}
}
private void login(String email, String password, HttpServletRequest req, HttpServletResponse res) throws ServletException, IOException {
PrintWriter out = res.getWriter();
boolean invalid = false;
try {
File acc = new File(System.getProperty("user.home"), "\\My Documents\\Accounts\\" + email.toLowerCase());
File pas = new File(acc, "password.txt");
BufferedReader buff = new BufferedReader(new FileReader(pas));
String storedPassword = buff.readLine();
if (storedPassword == null ? password == null : storedPassword.equals(password)) {
logined(req, res, email);
} else {
invalid = true;
}
} catch (IOException e) {
invalid = true;
} finally {
if (invalid == true) {
Path uri = Paths.get("E:/NetBeans HTML/Servlets/ServletsExample/build/web/WEB-INF/Login Sign Up.html");
Zucksnet ash = new Zucksnet("Zucksnet Style.css");
out.println("<html>\n<head>");
res.setContentType("text/css");
out.println("<style>");
String style[] = Zucksnet.getStyle();
for (int i = 0; i < style.length; i++) {
out.println(style[i]);
}
out.println("</style>");
out.println("<title>Login Failed!</title>\n</head>\n<body>");
res.setContentType("text/html");
out.println("Please Check Your Email or Password!");
out.println("</body>\n</html>");
}
}
}
private void logined(HttpServletRequest req, HttpServletResponse res, String email) throws IOException {
ImageServlet imageServlet = new ImageServlet();
imageServlet.setName(email);
PrintWriter out = res.getWriter();
String pathToWeb = getServletContext().getRealPath(File.separator);
Scanner scan;
File file = new File(pathToWeb, "Zucksnet Style.css");
scan = new Scanner(file);
res.setContentType("text/html");
out.println("<html>\n<head>\n<title>\nLogin\n</title>\n<style>");
res.setContentType("text/css");
while (scan.hasNextLine()) {
out.println(scan.nextLine());
}
out.println("</style>");
file = new File(pathToWeb, "home_script.txt");
scan = new Scanner(file);
while (scan.hasNextLine()) {
out.println(scan.nextLine());
}
file = new File(pathToWeb, "head.txt");
scan = new Scanner(file);
res.setContentType("text/html");
out.println("</head>\n<body id=\"homePage\" text=\"black\">");
while (scan.hasNextLine()) {
out.println(scan.nextLine());
}
out.println("<br><br>");
file = new File(pathToWeb, "body.txt");
scan = new Scanner(file);
while (scan.hasNextLine()) {
out.println(scan.nextLine());
}
out.println("</body>\n</html>");
}
}
HTML Source Code:-
<!DOCTYPE html>
<html>
<head>
<title>Login</title>
</head>
<body id="mobile" style="text-align: left; background-color: #294a8f; font-family: sans-serif; color: white;" onload="links(); buttons(); mobiles(); dob();">
<div align="left">
<form method="post" action="http://localhost:8084/ServletsExample/build/web/WEB-INF/classes/Login">
<table>
<tbody>
<tr>
<td><label for="email">E-mail</label></td><tr>
<td> <input name="email" type="email" id="email" autocomplete="off" placeholder="E-mail" autofocus style="font-kerning: auto; border-color: #294a8f; font-weight: bolder; background-color: #3B5998; color: white; text-spacing: none" size="32"/><tr>
<td><label for="password">Password</label></td><tr>
<td> <input name="password" type="password" id="password" autocomplete="off" placeholder="Password" style="font-kerning: auto; border-color: #294a8f; font-weight: bolder; background-color: #3B5998; color: white" size="32"/><tr>
<td><label for="remainLoggedIn" title="Remain Logged In on this Computer. Not recomonthended if using an shared Computer">
<input type="checkbox" id="remainLoggedIn" title="Remain Logged In on this Computer. Not recomonthended if using an shared Computer" style="appearance: checkbox; background-color: #3B5998; color: white"/>Remember me?</label><tr>
<td><button title="Login to your account" type="submit" style="background-color: #294a8f; border-color: #2C4272; appearance: push-button; color: white;">Login</button>
</tbody>
</table>
</form>
</div>
</body>
</html>
Comments