Commit f8fc182d authored by Fabian Dewantara Santonie's avatar Fabian Dewantara Santonie 🕊

Menambahkan Latihan 4

parent 07e019aa
package org.testing.inputName;
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 DataDiri
*/
@WebServlet("/DataDiri")
public class DataDiri extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public DataDiri() {
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 {
// TODO Auto-generated method stub
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 hobi = request.getParameter("hobi");
String email = request.getParameter("email");
String anak = request.getParameter("anak");
String pendidikan = request.getParameter("pendidikan");
String alamat = request.getParameter("alamat");
request.setAttribute("namaLengkap", namaLengkap);
request.setAttribute("namaPanggilan",namaPanggilan);
request.setAttribute("tempatLahir", tempatLahir);
request.setAttribute("tanggalLahir", tanggalLahir);
request.setAttribute("jenisKelamin", jenisKelamin);
request.setAttribute("hobi", hobi);
request.setAttribute("email", email);
request.setAttribute("anak", anak);
request.setAttribute("pendidikan", pendidikan);
request.setAttribute("alamat", alamat);
request.getRequestDispatcher("detailDataDiri.jsp").forward(request, response);
}
}
\ No newline at end of file
package org.testing.inputName;
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
*/
@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 {
// TODO Auto-generated method stub
response.setContentType("text/html;charset=UTF-8");
PrintWriter out = response.getWriter();
String username = request.getParameter("username");
String password = request.getParameter("password");
out.println("<html>");
out.println("<head>");
out.println("<link rel=\"stylesheet\" href=\"https://fonts.googleapis.com/css?family=Audiowide\">");
out.println("<style>");
out.println("body { font-family: \"Audiowide\", sans-serif;}");
out.println("</style>");
out.println("<title>Servlet Greetings</title>");
out.println("</head>");
out.println("<body>");
if(username != null && username.equalsIgnoreCase("fabian")) {
if(password != null && password.equals("fabian")) {
response.sendRedirect(request.getContextPath()+"/Registrasi.jsp");
}
else {
out.println("Password Salah!");
out.println("<a href=\"Latihan4.jsp\">Kembali Login</a>");
}
}
else {
out.println("Username Salah!");
out.println("<a href=\"Latihan4.jsp\">Kembali Login</a>");
}
out.println("</body>");
out.println("</html>");
}
}
...@@ -3,7 +3,6 @@ ...@@ -3,7 +3,6 @@
<!DOCTYPE html> <!DOCTYPE html>
<html> <html>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous"> <link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<head> <head>
<meta charset="ISO-8859-1"> <meta charset="ISO-8859-1">
<title>Insert title here</title> <title>Insert title here</title>
......
<%@ page language="java" contentType="text/html; charset=ISO-8859-1"
pageEncoding="ISO-8859-1"%>
<!DOCTYPE html>
<html>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body>
<div align="center">
<h1>Masukan Username dan Password</h1>
<form action="/belajarJavaServlet_Fabian/Latihan4" method ="POST">
<table style="with: 80%">
<tr>
<td>Username</td>
<td><input type="text" id="username" name="username" placeholder="Username..."></td>
</tr>
<tr>
<td>Password</td>
<td><input type="password" id="password" name="password" placeholder="Password..."></td>
</tr>
</table>
<input type="submit" value="Login">
</form>
</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>
<link href="https://cdn.jsdelivr.net/npm/bootstrap@5.0.2/dist/css/bootstrap.min.css" rel="stylesheet" integrity="sha384-EVSTQN3/azprG1Anm3QDgpJLIm9Nao0Yz1ztcQTwFspd3yD65VohhpuuCOmLASjC" crossorigin="anonymous">
<head>
<meta charset="ISO-8859-1">
<title>Insert title here</title>
</head>
<body style="background-color: aqua;">
<div class="form-group" align="center">
<h1>Masukan Username dan Password</h1>
<form action="/belajarJavaServlet_Fabian/DataDiri" method ="POST">
<table class="table">
<tr>
<td>Nama Lengkap</td>
<td><input type="text" class="form-control" id="namaLengkap" name="namaLengkap" maxlength="100" placeholder="Masukan Nama Lengkap..."></td>
</tr>
<tr>
<td>Nama Panggilan</td>
<td><input type="text" class="form-control" id="namaPanggilan" name="namaPanggilan" maxlength="10" placeholder="Masukan Nama Panggilan..."></td>
</tr>
<tr>
<td>Tempat Lahir</td>
<td><input type="text" class="form-control" id="tempatLahir" name="tempatLahir" placeholder="Masukan Tempat Lahir..."></td>
</tr>
<tr>
<td>Tanggal Lahir</td>
<td><input type="date" id="tanggalLahir" name="tanggalLahir" value="yyyy-mm-dd" min="1900-01-01" max="2020-01-01"></td>
</tr>
<tr>
<td>Jenis Kelamin</td>
<td><select id="jenisKelamin" name="jenisKelamin"> <option value="">--Pilih Jenis Kelamin--</option>
<option value="Laki-Laki">Laki-Laki</option> <option value="Perempuan">Perempuan</option> </select> </td>
</tr>
<tr>
<td>Hobi</td>
<td>
<input type="checkbox" id="hobiBerenang" name="hobiBerenang" value="Berenang"><label for="hobiBerenang">Berenang</label>
<input type="checkbox" id="hobiBuku" name="hobiBuku" value="Membaca Buku"><label for="hobiBuku">MembacaBuku</label>
<input type="checkbox" id="hobiFutsal" name="hobiFutsal" value="Futsal"><label for="hobiFutsal">Futsal</label>
<input type="checkbox" id="hobiBadminton" name="hobiBadminton" value="Badminton"><label for="hobiBadminton">Badminton</label>
<input type="checkbox" id="hobiLainnya" name="hobiLainnya" value="Lainnya"><label for="hobiLainnya">Lainnya</label>
</td>
</tr>
<tr>
<td>E-Mail</td>
<td><input type="email" class="form-control" id="email" name="email" placeholder="Masukan Alamat Email..."></td>
</tr>
<tr>
<td>Anak Ke</td>
<td><input type="number" class="form-control" id="anak" name="anak" min="1" max="15" placeholder="Dibatasi 1-15..."></td>
</tr>
<tr>
<td>Pendidikan</td>
<td>
<input type="radio" id="lulusanSD" name="pendidikan" value = "Tamatan SD"><label for="lulusanSD">SD</label>
<input type="radio" id="lulusanSMP" name="pendidikan" value="Tamatan SMP"><label for="lulusanSMP">SMP</label>
<input type="radio" id="lulusanSMA" name="pendidikan" value="Tamatan SMA"><label for="lulusanSMA">SMA</label>
<input type="radio" id="lulusanS1" name="pendidikan" value="Strata 1"><label for="lulusanS1">Strata 1</label>
<input type="radio" id="lulusanS2" name="pendidikan" value="Strata 2"><label for="lulusanS2">Strata 2</label>
<input type="radio" id="lulusanS3" name="pendidikan" value="Strata 3"><label for="lulusanS3">Strata 3</label>
</td>
</tr>
<tr>
<td>Alamat</td>
<td><textarea class="form-control" id="alamat" name="alamat" placeholder="Masukan Alamat Anda..."></textarea></td>
</tr>
</table>
<input type="submit" value="Submit Data">
</form>
</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>
<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>E-Mail</th>
<th>Anak Ke</th>
<th>Pendidikan</th>
<th>Alamat</th>
</tr>
<tr>
<th>${namaLengkap}</th>
<th>${namaPanggilan}</th>
<th>${tempatLahir}</th>
<th>${tanggalLahir}</th>
<th>${jenisKelamin}</th>
<th>${Hobi}</th>
<th>${email}</th>
<th>${anak}</th>
<th>${pendidikan}</th>
<th>${alamat}</th>
</tr>
</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