Commit 4467f519 authored by Dwinowo Muhammad's avatar Dwinowo Muhammad

Menambahkan Latihan 4. Akses lewat Index.jsp

username : Agus
password : agus17
parent 884642b5
package com.latihan4;
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
*/
@WebServlet("/Latihan4")
public class Latihan4 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Latihan4() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
String namaLengkap = request.getParameter("namaLengkap");
String namaPanggilan = request.getParameter("namaPanggilan");
String tempatLahir = request.getParameter("tempatLahir");
String tanggalLahir = request.getParameter("tanggalLahir");
String jenisKelamin = request.getParameter("jenisKelamin");
String futsal = request.getParameter("futsal");
String badminton = request.getParameter("badminton");
String membaca = request.getParameter("membaca");
String renang = request.getParameter("renang");
String email = request.getParameter("email");
String anakKe = request.getParameter("anakKe");
String pendidikanTerkahir = request.getParameter("pendidikanTerakhir");
String alamat = request.getParameter("alamat");
String hobi = "";
request.setAttribute("namaLengkap", namaLengkap);
request.setAttribute("namaPanggilan", namaPanggilan);
request.setAttribute("tempatLahir", tempatLahir);
request.setAttribute("tanggalLahir", tanggalLahir);
request.setAttribute("jenisKelamin", jenisKelamin);
try {
if (futsal.equals("Futsal")) {
hobi = hobi + futsal + " ";
}
} catch (Exception e) {
}
try {
if (badminton.equals("Badminton")) {
hobi = hobi + badminton + " ";
}
} catch (Exception e) {
}
try {
if (membaca.equals("Membaca")) {
hobi = hobi + membaca + " ";
}
} catch (Exception e) {
}
try {
if (renang.equals("Renang")) {
hobi = hobi + renang + " ";
}
} catch (Exception e) {
}
request.setAttribute("hobi", hobi);
request.setAttribute("email", email);
request.setAttribute("anakKe", anakKe);
request.setAttribute("pendidikanTerakhir", pendidikanTerkahir);
request.setAttribute("alamat", alamat);
request.getRequestDispatcher("detailDaftarKaryawan.jsp").forward(request, response);
doGet(request, response);
}
}
package com.latihan4;
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 login
*/
@WebServlet("/login")
public class login extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public login() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
// TODO Auto-generated method stub
response.getWriter().append("Served at: ").append(request.getContextPath());
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse
* response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response)
throws ServletException, IOException {
PrintWriter out = response.getWriter();
String userName = request.getParameter("username").toString();
String password = request.getParameter("password").toString();
String passwordAgus = "agus17";
String userAgus = "Agus";
if (password.equals(passwordAgus) && userName.equals(userAgus)) {
HttpSession session = request.getSession(true);
session.putValue("username", userName);
request.setAttribute("username", userName);
request.getRequestDispatcher("Latihan4.jsp").forward(request, response);
request.getRequestDispatcher("detailDaftarKaryawan.jsp").forward(request, response);
response.sendRedirect(request.getContextPath() + "/Latihan4.jsp");
} else if (!password.equals(passwordAgus) && !userName.equals(userAgus)) {
out.println("<h1> Login Gagal </h1>");
out.println("<p> Username dan password anda salah!!! </p>");
out.println("<a href=\"login.jsp\"><button>Kembali</button></a>");
} else if (!userName.equals(userAgus)) {
out.println("<h1> Login Gagal </h1>");
out.println("<p> Username anda salah!!! </p>");
out.println("<a href=\"login.jsp\"><button>Kembali</button></a>");
} else if (!password.equals(passwordAgus)) {
out.println("<h1> Login Gagal </h1>");
out.println("<p> Password anda salah!!! </p>");
out.println("<a href=\"login.jsp\"><button>Kembali</button></a>");
}
doGet(request, response);
}
}
......@@ -6,6 +6,7 @@
<meta charset="ISO-8859-1">
<title>Latihan3</title>
<link rel="stylesheet" href="styles.css">
<link rel="shortcut icon" href="https://bit.ly/3qqTW6D" />
</head>
<body>
......
<%@ 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 Tambah Data Karyawan</title>
<meta name="viewport" content="width=device-width, initial-scale=1.0">
<link rel="stylesheet" href="cssLatihan4.css">
<link href='https://fonts.googleapis.com/css?family=Nunito:400,300'
rel='stylesheet' type='text/css'>
</head>
<body>
<h2>Anda login sebagai : ${username}</h2>
<h1>Form Tambah Data Karyawan</h1>
<form method="post" action="Latihan4" id="inputDataKaryawan">
<fieldset>
Nama : <input type="text" name="namaLengkap" maxlength="100"></br>
Nama Panggilan : <input type="text" name="namaPanggilan"
maxlength="10"></br> Tempat Lahir : <input type="text"
name="tempatLahir"></br> Tanggal Lahir : <input type="date"
name="tanggalLahir" /></br> Jenis Kelamin : <select id="jenisKelamin"
name="jenisKelamin">
<option value="Laki-laki">Laki - laki</option>
<option value="Perempuan">Perempuan</option>
</select></br> Hobi : </br> <input type="checkbox" id="futsal" name="futsal"
value="Futsal"> <label for="futsal" class="light">Futsal</label><br>
<input type="checkbox" id="badminton" name="badminton"
value="Badminton"> <label for="badminton" class="light">Badminton</label><br>
<input type="checkbox" id="membaca" name="membaca" value="Membaca">
<label for="membaca" class="light">Membaca</label><br> <input
type="checkbox" id="renang" name="renang" value="Renang"> <label
for="renang" class="light">Renang</label></br> <br> Email : <input
type="email" name="email"></br> Anak ke : <input type="number"
id="anakKe" name="anakKe" min="1" max="15"></br> Pendidikan
Terakhir : <br> <input type="radio" id="smp"
name="pendidikanTerakhir" value="SMP"> <label for="smp"
class="light">SMP</label><br> <input type="radio"
id="sma/smk/sederajat" name="pendidikanTerakhir"
value="SMA/SMK/Sederajat" class="light"> <label
for="sma/smk/sederajat" class="light">SMA/SMK/Sederajat</label><br>
<input type="radio" id="s1" name="pendidikanTerakhir"
value="Strata 1"> <label for="s1" class="light">Strata
1</label><br> <input type="radio" id="s2" name="pendidikanTerakhir"
value="Strata 2"> <label for="s2" class="light">Strata
2</label><br> <input type="radio" id="s3" name="pendidikanTerakhir"
value="Strata 3"> <label for="s3" class="light">Strata
3</label></br> <br> Alamat :
<textarea rows="4" cols="50" name="alamat"></textarea>
</fieldset>
<input type="submit" value="Submit" class="tombolRegister"> <input
type="reset" value="Reset" class="tombolReset">
</form>
</body>
</html>
\ No newline at end of file
@charset "ISO-8859-1";
*, *:before, *:after {
-moz-box-sizing: border-box;
-webkit-box-sizing: border-box;
box-sizing: border-box;
}
body {
font-family: 'Nunito', sans-serif;
color: #384047;
}
form {
max-width: 300px;
margin: 10px auto;
padding: 10px 20px;
background: #f4f7f8;
border-radius: 8px;
}
h1 {
margin: 0 0 30px 0;
text-align: center;
}
input[type="text"],
input[type="password"],
input[type="date"],
input[type="datetime"],
input[type="email"],
input[type="number"],
input[type="search"],
input[type="tel"],
input[type="time"],
input[type="url"],
textarea,
select {
background: rgba(255,255,255,0.1);
border: none;
font-size: 16px;
height: auto;
margin: 0;
outline: 0;
padding: 15px;
width: 100%;
background-color: #e8eeef;
color: #8a97a0;
box-shadow: 0 1px 0 rgba(0,0,0,0.03) inset;
margin-bottom: 30px;
}
input[type="radio"],
input[type="checkbox"] {
margin: 0 4px 8px 0;
}
select {
padding: 6px;
height: 32px;
border-radius: 2px;
}
.button {
padding: 19px 39px 18px 39px;
color: #FFF;
background-color: #c94b4b;
font-size: 18px;
text-align: center;
font-style: normal;
border-radius: 5px;
width: 100%;
border: 1px solid #c13a3a;
border-width: 1px 1px 3px;
box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
margin-bottom: 10px;
}
.tombolRegister {
padding: 19px 39px 18px 39px;
color: #FFF;
background-color: #4bc970;
font-size: 18px;
text-align: center;
font-style: normal;
border-radius: 5px;
width: 100%;
border: 1px solid #3ac162;
border-width: 1px 1px 3px;
box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
margin-bottom: 10px;
cursor: pointer;
}
.tombolReset {
padding: 19px 39px 18px 39px;
color: #FFF;
background-color: #c94b4b;
font-size: 18px;
text-align: center;
font-style: normal;
border-radius: 5px;
width: 100%;
border: 1px solid #c13a3a;
border-width: 1px 1px 3px;
box-shadow: 0 -1px 0 rgba(255,255,255,0.1) inset;
margin-bottom: 10px;
cursor: pointer;
}
fieldset {
margin-bottom: 30px;
border: none;
}
legend {
font-size: 1.4em;
margin-bottom: 10px;
}
label {
display: block;
margin-bottom: 8px;
}
label.light {
font-weight: 300;
display: inline;
}
.number {
background-color: #5fcf80;
color: #fff;
height: 30px;
width: 30px;
display: inline-block;
font-size: 0.8em;
margin-right: 4px;
line-height: 30px;
text-align: center;
text-shadow: 0 1px 0 rgba(255,255,255,0.2);
border-radius: 100%;
}
@media screen and (min-width: 480px) {
form {
max-width: 480px;
}
}
\ 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>Insert title here</title>
</head>
<body>
<h1>Anda login sebagai : ${username}</h1>
<b>Selamat data anda berhasil di buat</b>
<table border="2">
<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>${namaLengkap}</td>
<td>${namaPanggilan}</td>
<td>${tempatLahir}</td>
<td>${tanggalLahir}</td>
<td>${jenisKelamin}</td>
<td>${hobi}</td>
<td>${email}</td>
<td>${anakKe}</td>
<td>${pendidikanTerakhir}</td>
<td>${alamat}</td>
</tr>
</table>
</body>
</html>
\ No newline at end of file
......@@ -13,7 +13,7 @@
<li><a href="Latihan1.jsp">Latihan 1</a></li>
<li><a href="Latihan2.jsp">Latihan 2</a></li>
<li><a href="Latihan3.jsp">Latihan 3</a></li>
<li>Latihan 4</li>
<li><a href="login.jsp">Latihan 4</a></li>
<li>Latihan 5</li>
</ul>
......
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<head>
<meta charset="ISO-8859-1">
<title>Latihan 4</title>
<link rel="stylesheet" href="styles.css">
</head>
<body>
<div id="wrapper">
<div class="main-content">
<div class="header">
<form action="login" method="post">
<label for="fname">Username:</label><br> <input type="text"
placeholder="username" class="input-1" id="username"
name="username"><br> <label for="lname">Password:</label><br>
<input type="password" placeholder="password" class="input-2"
id="password" name="password"><br> <br>
<input class="btn" type="submit" value="Submit">
</form>
</div>
</div>
</div>
</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