Commit c135107a authored by Dio Harvandy's avatar Dio Harvandy

Latihan 3

Input username dan password
parent b02fd605
Pipeline #6522 canceled with stages
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;
/**
* Servlet implementation class Latihan3
*/
@WebServlet("/Latihan3")
public class Latihan3 extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public Latihan3() {
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");
String username = "dio";
String password = "123";
PrintWriter out = response.getWriter();
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>");
}
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='Latihan3.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='Latihan3.jsp'>Kembali</a></h3>");
out.println("</body>");
out.println("</hmtl>");
}
System.out.println("Service");
}
}
<%@ 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 action="Latihan3" 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>Password</label></td>
<td>: <input name = "password" type = "password"></td>
</tr>
<tr>
<th colspan="2" style="padding: 10px"><button type = "submit">Submit</button></th>
</tr>
</table>
</form>
</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