Commit a46f98ed authored by Dio Harvandy's avatar Dio Harvandy

Latihan 4

Membuat modul login, tambah data dan tampil data karyawan
parent 820756dc
......@@ -8,6 +8,7 @@ import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class Latihan3
......@@ -35,6 +36,7 @@ public class Latihan3 extends HttpServlet {
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
@SuppressWarnings("deprecation")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String username = "dio";
......@@ -43,15 +45,9 @@ public class Latihan3 extends HttpServlet {
String usernameRes = request.getParameter("username").toString();
String passwordRes = request.getParameter("password").toString();
if(username.equals(usernameRes) && password.equals(passwordRes)) {
out.println("<hmtl>");
out.println("<head>");
out.println("<title>Latihan 3 Sukses</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1 style='text-align: center;'>Login Sukses</h1>");
out.println("<h3 style='text-align: center;'>Selamat Datang "+username.toUpperCase()+"</h3>");
out.println("</body>");
out.println("</hmtl>");
HttpSession session = request.getSession(true);
session.putValue("username", usernameRes);
response.sendRedirect(request.getContextPath()+"/Latihan3-1");
}
else if(!username.equals(usernameRes)) {
out.println("<hmtl>");
......
package com.latihan.web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class Latihan3_1
*/
@WebServlet("/Latihan3-1")
public class Latihan3_1 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Latihan3_1() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
HttpSession session = request.getSession(true);
@SuppressWarnings("deprecation")
String usernameRes = session.getValue("username").toString();
out.println("<hmtl>");
out.println("<head>");
out.println("<title>Latihan 3 Sukses</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1 style='text-align: center;'>Login Sukses</h1>");
out.println("<h3 style='text-align: center;'>Selamat Datang "+usernameRes.toUpperCase()+"</h3>");
out.println("</body>");
out.println("</hmtl>");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
package com.latihan.web;
import java.io.IOException;
import java.io.PrintWriter;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import javax.servlet.http.HttpSession;
/**
* Servlet implementation class Latihan4_login
*/
@WebServlet("/latihan4-login")
public class Latihan4_login extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Latihan4_login() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
@SuppressWarnings("deprecation")
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession(true);
String usernameRes = session.getValue("username").toString();
String emailRes = session.getValue("email").toString();
request.setAttribute("username", usernameRes);
request.setAttribute("email", emailRes);
request.getRequestDispatcher("Latihan4_tambahKaryawan.jsp").forward(request, response);
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
@SuppressWarnings("deprecation")
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
response.setContentType("text/html;charset=UTF-8");
String username = "dio";
String email = "dioharvandy21@gmail.com";
String password = "123";
PrintWriter out = response.getWriter();
String usernameRes = request.getParameter("username").toString();
String emailRes = request.getParameter("email").toString();
String passwordRes = request.getParameter("password").toString();
if(username.equals(usernameRes) && password.equals(passwordRes) && email.equals(emailRes)) {
HttpSession session = request.getSession(true);
session.putValue("username", usernameRes);
session.putValue("email", emailRes);
response.sendRedirect(request.getContextPath()+"/latihan4-login");
}
else if(!username.equals(usernameRes)) {
out.println("<hmtl>");
out.println("<head>");
out.println("<title>Latihan 3 Gagal</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1 style='text-align: center;'>Login Gagal</h1>");
out.println("<h3 style='text-align: center;'>Username Anda Salah</h3>");
out.println("<h3 style='text-align: center;'><a href='Latihan4_login.jsp'>Kembali</a></h3>");
out.println("</body>");
out.println("</hmtl>");
}
else if(!password.equals(passwordRes)) {
out.println("<hmtl>");
out.println("<head>");
out.println("<title>Latihan 3 Gagal</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1 style='text-align: center;'>Login Gagal</h1>");
out.println("<h3 style='text-align: center;'>Password Anda Salah</h3>");
out.println("<h3 style='text-align: center;'><a href='Latihan4_login.jsp'>Kembali</a></h3>");
out.println("</body>");
out.println("</hmtl>");
}
else if(!email.equals(emailRes)) {
out.println("<hmtl>");
out.println("<head>");
out.println("<title>Latihan 3 Gagal</title>");
out.println("</head>");
out.println("<body>");
out.println("<h1 style='text-align: center;'>Login Gagal</h1>");
out.println("<h3 style='text-align: center;'>Email Anda Salah</h3>");
out.println("<h3 style='text-align: center;'><a href='Latihan4_login.jsp'>Kembali</a></h3>");
out.println("</body>");
out.println("</hmtl>");
}
System.out.println("Service");
}
}
package com.latihan.web;
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.annotation.WebServlet;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
/**
* Servlet implementation class Latihan4_tambahKaryawan
*/
@WebServlet("/latihan4-tambahkaryawan")
public class Latihan4_tambahKaryawan extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Latihan4_tambahKaryawan() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
request.setAttribute("username", request.getParameter("username").toString());
request.setAttribute("email", request.getParameter("email").toString());
request.setAttribute("nama", request.getParameter("nama").toString());
request.setAttribute("namaPanggilan", request.getParameter("namaPanggilan").toString());
request.setAttribute("tempatLahir", request.getParameter("tempatLahir").toString());
request.setAttribute("tanggalLahir", request.getParameter("tanggalLahir").toString());
request.setAttribute("jenisKelamin", request.getParameter("jenisKelamin").toString());
request.setAttribute("hobi1", request.getParameter("hobi1"));
request.setAttribute("hobi2", request.getParameter("hobi2"));
request.setAttribute("hobi3", request.getParameter("hobi3"));
request.setAttribute("hobi4", request.getParameter("hobi4"));
request.setAttribute("hobi5", request.getParameter("hobi5"));
request.setAttribute("email", request.getParameter("email").toString());
request.setAttribute("anakKe", request.getParameter("anakKe").toString());
request.setAttribute("pddTerakhir", request.getParameter("pddTerakhir").toString());
request.setAttribute("alamat", request.getParameter("alamat").toString());
request.getRequestDispatcher("Latihan4_tampilKaryawan.jsp").forward(request, response);
System.out.println("Service");
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
}
}
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<style type="text/css">
.button{
padding: 10px 27px;
text-align: center;
font-size: 10px;
cursor: pointer;
}
.blue {
background-color: #188bf0;
color: white;
}
</style>
<title>Insert title here</title>
</head>
<body>
<form action="latihan4-login" method="post">
<table style="border: 1px solid; margin: auto;">
<tr>
<th colspan="2" style="padding: 10px">Login</th>
</tr>
<tr>
<td><label>Username</label></td>
<td>: <input name = "username" type = "text"></td>
</tr>
<tr>
<td><label>Email</label></td>
<td>: <input name = "email" type = "text"></td>
</tr>
<tr>
<td><label>Password</label></td>
<td>: <input name = "password" type = "password"></td>
</tr>
<tr>
<th colspan="2" style="padding: 10px"><button class="button blue" type = "submit">Submit</button></th>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Form Karyawan</title>
<style type="text/css">
.button{
padding: 10px 27px;
text-align: center;
font-size: 10px;
cursor: pointer;
}
.blue {
background-color: #188bf0;
color: white;
}
.yellow {
background-color: #e9f018;
color: black;
}
</style>
</head>
<body>
<form action="latihan4-tambahkaryawan" method="get">
<input type="hidden" name="username" value = "${username}">
<input type="hidden" name="email" value = "${email}">
<table style="border: 1px solid; margin: auto;">
<tr>
<th colspan="2" style="padding: 10px"> Username : ${username}</th>
</tr>
<tr>
<th colspan="2" style="padding: 10px">Email : ${email}</th>
</tr>
<tr>
<th style="border: 1px solid;" colspan="2"><h3>Form Tambah Karyawan</h3></th>
</tr>
<tr>
<td><label>Nama</label></td>
<td>: <input name = "nama" type = "text" maxlength="100" required></td>
</tr>
<tr>
<td><label>Nama Panggilan</label></td>
<td>: <input name = "namaPanggilan" type = "text" maxlength="10" required></td>
</tr>
<tr>
<td><label>Tempat Lahir</label></td>
<td>: <input name = "tempatLahir" type = "text" required></td>
</tr>
<tr>
<td><label>Tanggal Lahir</label></td>
<td>: <input name = "tanggalLahir" type = "date" required></td>
</tr>
<tr>
<td><label>Jenis Kelamin</label></td>
<td>: <select name="jenisKelamin">
<option value="Laki-Laki">Laki-Laki</option>
<option value="Perempuan">Perempuan</option>
</select>
</td>
</tr>
<tr>
<td><label>Hobi</label></td>
<td>: <input name = "hobi1" value="Berenang" type = "checkbox">
<label>Berenang</label>
<input name = "hobi2" value="Membaca Buku" type = "checkbox">
<label>Membaca Buku</label>
<input name = "hobi3" value="Futsal" type = "checkbox">
<label>Futsal</label>
<input name = "hobi4" value="Badminton" type = "checkbox">
<label>Badminton</label>
<input name = "hobi5" value="Lainnya" type = "checkbox">
<label>Lainnya</label>
</td>
</tr>
<tr>
<td><label>Email</label></td>
<td>: <input name = "email" type = "email" required></td>
</tr>
<tr>
<td><label>Anak Ke</label></td>
<td>: <input name = "anakKe" type = "number" min="1" max="15" required></td>
</tr>
<tr>
<td><label>Pendidikan Terakhir</label></td>
<td>: <input name = "pddTerakhir" value="SMP" type = "radio" checked>
<label>SMP</label>
<input name = "pddTerakhir" value="SMA" type = "radio">
<label>SMA/SMK/Sederajat</label>
<input name = "pddTerakhir" value="Strata 1" type = "radio">
<label>Strata 1</label>
<input name = "pddTerakhir" value="Strata 2" type = "radio">
<label>Strata 2</label>
<input name = "pddTerakhir" value="Strata 3" type = "radio">
<label>Strata 3</label>
</td>
</tr>
<tr>
<td><label>Alamat</label></td>
<td>: <textarea rows="2" cols="60" name="alamat" required></textarea></td>
</tr>
<tr>
<th colspan="2" style="padding: 10px"><button class="button yellow" type = "reset">Reset</button>
<button class="button blue" type = "submit">Submit</button></th>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<style>
table, td, th {
border: 1px solid;
padding: 5px;
}
</style>
<title>Tampil Karyawan</title>
</head>
<body>
<p style="text-align: center;">Data Berhasil Disubmit !!!</p>
<h3 style="text-align: center;">Username : ${username}</h3>
<h3 style="text-align: center;">Email : ${email}</h3>
<table style="margin: auto; border-collapse: collapse;">
<tr>
<th colspan="10" style="padding: 10px">Data Karyawan</th>
</tr>
<tr>
<th>Nama</th>
<th>Nama Panggilan</th>
<th>Tempat Lahir</th>
<th>Tanggal Lahir</th>
<th>Jenis Kelamin</th>
<th>Hobi</th>
<th>Email</th>
<th>Anak Ke</th>
<th>Pendidikan Terakhir</th>
<th>Alamat</th>
</tr>
<tr>
<td>${nama}</td>
<td>${namaPanggilan}</td>
<td>${tempatLahir}</td>
<td>${tanggalLahir}</td>
<td>${jenisKelamin}</td>
<td>${hobi1} ${hobi2} ${hobi3} ${hobi4} ${hobi5}</td>
<td>${email}</td>
<td>${anakKe}</td>
<td>${pddTerakhir}</td>
<td>${alamat}</td>
</tr>
</table>
</body>
</html>
\ No newline at end of file
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment