Commit aa1477ad authored by Hanif Dwitama Putera's avatar Hanif Dwitama Putera

Latihan 4 Membuat form data lengkap

parent 3c21d41c
package com.minggu3.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 FilterUsernamePasswordLat4
*/
@WebServlet("/FilterUsernamePasswordLat4")
public class FilterUsernamePasswordLat4 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public FilterUsernamePasswordLat4() {
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 {
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String namaUsername = "Budi";
String namaPassword = "123";
String username = request.getParameter("inputUsername");
String password = request.getParameter("inputPassword");
if (username.equals(namaUsername) && password.equals(namaPassword)) {
out.println("Login Sukses");
out.println("");
out.println("Selamat Datang Budi");
} else if (!username.equals(namaUsername) && password.equals(namaPassword)) {
out.println("Login Gagal");
out.println("");
out.println("Username anda salah");
} else if (username.equals(namaUsername) && !password.equals(namaPassword)) {
out.println("Login Gagal");
out.println("");
out.println("Password anda salah");
} else if (!username.equals(namaUsername) && !password.equals(namaPassword)) {
out.println("Login Gagal");
out.println("");
out.println("Username anda salah");
}
if (username.equals(namaUsername) && password.equals(namaPassword)) {
HttpSession session = request.getSession(true);
session.putValue("username", username);
response.sendRedirect(request.getContextPath() + "/Latihan4/FormPengisian.jsp");
}
System.out.println("Service");
}
}
package com.minggu3.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 IsiForm
*/
@WebServlet("/IsiForm")
public class IsiForm extends HttpServlet {
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 berenang = request.getParameter("berenang");
String membacaBuku = request.getParameter("membacaBuku");
String futsal = request.getParameter("futsal");
String badminton = request.getParameter("badminton");
String lainnya = request.getParameter("lainnya");
String email = request.getParameter("email");
String anakKe = request.getParameter("anakKe");
String pendidikanTerakhir = request.getParameter("pendidikan");
String alamat = request.getParameter("alamat");
request.setAttribute("username", "hanif");
request.setAttribute("namaLengkap", namaLengkap);
request.setAttribute("namaPanggilan", namaPanggilan);
request.setAttribute("tempatLahir", tempatLahir);
request.setAttribute("tanggalLahir", tanggalLahir);
request.setAttribute("jenisKelamin", jenisKelamin);
request.setAttribute("berenang", berenang);
request.setAttribute("membacaBuku", membacaBuku);
request.setAttribute("futsal", futsal);
request.setAttribute("badminton", badminton);
request.setAttribute("lainnya", lainnya);
request.setAttribute("email", email);
request.setAttribute("anakKe", anakKe);
request.setAttribute("pendidikanTerakhir", pendidikanTerakhir);
request.setAttribute("alamat", alamat);
request.getRequestDispatcher("Latihan4/DetailIsiForm.jsp").forward(request, response);
}
}
package com.testing.web2;
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 daftarLogin
*/
@WebServlet("/daftarLogin")
public class daftarLogin extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public daftarLogin() {
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 uname = request.getParameter("uname");
String uemail = request.getParameter("uemail");
String upass = request.getParameter("upass");
request.setAttribute("uname", uname);
request.setAttribute("uemail", uemail);
request.setAttribute("upass", upass);
request.getRequestDispatcher("detailDaftarLogin.jsp").forward(request, response);
}
}
<%@ 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>
<form method="post" action="IsiForm">
Nama: <input type="text" name="uname"></br>
Email: <input type="text" name="uemail"></br>
Password: <input type="password" name="upass"></br>
<input type="submit" value="register">
</form>
</body>
</html>
\ No newline at end of file
......@@ -5,31 +5,9 @@
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<link href="http://localhost:8080/latihanJavaServlet_Hanif/style.css"
rel="stylesheet" type="text/css">
</head>
<style>
.semua {
margin: auto;
text-align: center;
}
body {
height: 100%;
margin: 0;
background: #71797E;
}
.container {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
h1 {
padding-bottom: 10px;
}
</style>
<body>
<div class="container">
<h1 class="semua">Testing Nama Get</h1>
......@@ -43,6 +21,8 @@ h1 {
id="lname" name="lname" value=""><br> <br> <input
type="submit" value="Submit">
</form>
<a href="http://localhost:8080/latihanJavaServlet_Hanif/index.jsp">Kembali
ke Pilihan Latihan</a>
</div>
</div>
</body>
......
......@@ -5,31 +5,9 @@
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<link href="http://localhost:8080/latihanJavaServlet_Hanif/style.css"
rel="stylesheet" type="text/css">
</head>
<style>
.semua {
margin: auto;
text-align: center;
}
body {
height: 100%;
margin: 0;
background: #71797E;
}
.container {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
h1 {
padding-bottom: 10px;
}
</style>
<body>
<div class="container">
<h1 class="semua">Testing Log in</h1>
......@@ -37,12 +15,14 @@ h1 {
<form name="form"
action="http://localhost:8080/latihanJavaServlet_Hanif/FilterUsernamePassword"
method="post">
<label for="fname">Username:</label><br>
<input type="text" id="inputUsername" name="inputUsername" value=""><br>
<label for="lname">Password:</label><br>
<input type="password" id="inputPassword" name="inputPassword" value=""><br><br>
<input type="submit" value="Submit">
<label for="fname">Username:</label><br> <input type="text"
id="inputUsername" name="inputUsername" value=""><br>
<label for="lname">Password:</label><br> <input type="password"
id="inputPassword" name="inputPassword" value=""><br>
<br> <input type="submit" value="Submit">
</form>
<a href="http://localhost:8080/latihanJavaServlet_Hanif/index.jsp">Kembali
ke Pilihan Latihan</a>
</div>
</div>
</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>Insert title here</title>
</head>
<body>
<b>Selamat datang ${username}</b>
<table border="2">
<tr>
<th>Nama Lengkap</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>${berenang} ${badminton} ${membacaBuku} ${lainnya} ${futsal}</td>
<td>${email}</td>
<td>${anakKe}</td>
<td>${pendidikanTerakhir}</td>
<td>${alamat}</td>
</tr>
</table>
</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>Insert title here</title>
</head>
<body>
<div class="container">
<h1 class="semua">Pengisian Form</h1>
<div class="semua">
<form name="formnama"
action="../IsiForm"
method="post">
<label for="namaLengkap">Nama</label>
<input type="text" id="" name="namaLengkap" max="100"><br>
<label for="namaPanggilan">Nama Panggilan</label>
<input type="text" id="" name="namaPanggilan" max="10"><br>
<label for="tempatLahir">Tempat Lahir</label>
<input type="text" id="" name="tempatLahir"><br>
<label for="tanggalLahir">Tanggal Lahir</label>
<input type="date" id="" name="tanggalLahir"><br>
<label for="jenisKelamin">Jenis Kelamin</label>
<select id="" name="jenisKelamin">
<option value="Laki-Laki">Laki-Laki</option>
<option value="Perempuan">Perempuan</option>
</select><br>
<label for="hobi">hobi</label>
<input type="checkbox" id="" name="berenang" value="Berenang">
<label for="berenang">Berenang</label>
<input type="checkbox" id="" name="membacaBuku" value="Membaca Buku">
<label for="membacaBuku">Membaca Buku</label>
<input type="checkbox" id="" name="futsal" value="Futsal">
<label for="futsal">Futsal</label>
<input type="checkbox" id="" name="badminton" value="Badminton">
<label for="badminton">Badminton</label>
<input type="checkbox" id="" name="lainnya" value="Lainnya">
<label for="lainnya">Lainnya</label><br>
<label for="email">Email</label>
<input type="email" id="" name="email"><br>
<label for="anakKe">Anak ke</label>
<input type="number" id="" name="anakKe" value="" min="1" max="15"><br>
<label for="pendidikanTerakhir">Pendidikan Terakhir</label>
<input type="radio" id="" name="pendidikan" value="SMP">
<label for="smp">SMP</label>
<input type="radio" id="" name="pendidikan" value="SMA/SMK/MA">
<label for="smaDkk">SMA/SMK/Sederajat</label>
<input type="radio" id="" name="pendidikan" value="Strata 1">
<label for="strata1">Strata 1</label>
<input type="radio" id="" name="pendidikan" value="Strata 2">
<label for="strata2">Strata 2</label>
<input type="radio" id="" name="pendidikan" value="Strata 3">
<label for="strata3">Strata 3</label><br>
<label for="textArea">Alamat</label>
<textarea rows="4" cols="50" name="alamat"></textarea><br>
<br>
<input type="submit" value="Submit">
<input type="submit" value="Reset">
</form>
<a href="http://localhost:8080/latihanJavaServlet_Hanif/index.jsp">Kembali
ke Pilihan Latihan</a>
</div>
</div>
</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>Insert title here</title>
<link href="http://localhost:8080/latihanJavaServlet_Hanif/style.css"
rel="stylesheet" type="text/css">
</head>
<body>
<div class="container">
<h1 class="semua">Testing Log in</h1>
<div class="semua">
<form name="form"
action="http://localhost:8080/latihanJavaServlet_Hanif/FilterUsernamePasswordLat4"
method="post">
<label for="fname">Username:</label><br> <input type="text"
id="inputUsername" name="inputUsername" value=""><br>
<label for="lname">Password:</label><br> <input type="password"
id="inputPassword" name="inputPassword" value=""><br>
<br> <input type="submit" value="Submit">
</form>
<a href="http://localhost:8080/latihanJavaServlet_Hanif/index.jsp">Kembali
ke Pilihan Latihan</a>
</div>
</div>
</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>Insert title here</title>
</head>
<body>
<b>Selamat data berhasil dibuat</b>
<table border="2">
<tr>
<th>Username</th>
<th>Email</th>
<th>Password</th>
</tr>
<tr>
<td>${uname}</td>
<td>${uemail}</td>
<td>${upass}</td>
</tr>
</table>
</body>
</html>
\ No newline at end of file
......@@ -32,7 +32,8 @@
</p>
<p>
<a href="http://localhost:8080/latihanJavaServlet_Hanif/testing04">Latihan
<a
href="http://localhost:8080/latihanJavaServlet_Hanif/Latihan4/Latihan4.jsp">Latihan
4</a>
</p>
......
......@@ -5,31 +5,9 @@
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
<link href="http://localhost:8080/latihanJavaServlet_Hanif/style.css"
rel="stylesheet" type="text/css">
</head>
<style>
.semua {
margin: auto;
text-align: center;
}
body {
height: 100%;
margin: 0;
background: #71797E;
}
.container {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
h1 {
padding-bottom: 10px;
}
</style>
<body>
<div class="container">
<h1 class="semua">Testing Nama Get</h1>
......@@ -43,6 +21,8 @@ h1 {
id="lname" name="lname" value=""><br> <br> <input
type="submit" value="Submit">
</form>
<a href="http://localhost:8080/latihanJavaServlet_Hanif/index.jsp">Kembali
ke Pilihan Latihan</a>
</div>
</div>
</body>
......
@charset "ISO-8859-1";
* {
padding: 0;
margin: 0;
color: #1a1f36;
box-sizing: border-box;
word-wrap: break-word;
font-family: -apple-system, BlinkMacSystemFont, Segoe UI, Roboto,
Helvetica Neue, Ubuntu, sans-serif;
}
body {
min-height: 100%;
background-color: #ffffff;
}
h1 {
letter-spacing: -1px;
}
a {
color: #5469d4;
text-decoration: unset;
}
.semua {
margin: auto;
text-align: center;
}
body {
height: 100%;
margin: 0;
background: #ffffff;
}
.container {
margin: 0;
position: absolute;
top: 50%;
left: 50%;
transform: translate(-50%, -50%);
}
h1 {
padding-bottom: 10px;
}
\ 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