Commit f149d5b7 by Sahala Zico Simamora

add README

parents
Manifest-Version: 1.0
Class-Path:
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login</title>
</head>
<body>
<section class="loginSection">
<form action="login.do" method="post">
<table>
<tr>
<td>Username </td>
<td> <input type="text" name="username"></td>
</tr>
<tr>
<td>password </td>
<td> <input type="password" name="password"></td>
</tr>
<tr>
<td colspan="2" align="right"> <input type="submit" name="login" value="Log In"></td>
</tr>
</table>
</form>
</section>
</body>
</html>
\ No newline at end of file
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Login Failed</title>
</head>
<body>
<a href="login.jsp">Back..</a>
<p>Username dan Password Salah</p>
</body>
</html>
\ No newline at end of file
<%@page import="org.perpustakaan.models.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>Admin</title>
</head>
<body>
<section class="user">
<p>Hello <%=session.getAttribute("username") %></p>
<form action="controller.servlet" method="get">
<input type="submit" name="btnControl" value="logout">
</form>
</section>
<% Buku b = Autentifikasi.buku;%>
<section class="data">
<table>
<tr>
<th>ID</th>
<th>Judul</th>
<th>Status</th>
<th>Option</th>
</tr>
<tr>
<td><%= b.getId()%></td>
<td><%= b.getJudul()%></td>
<td><%= b.getStatus()%></td>
<td>
<form action="controller.servlet" method="post">
<input type="submit" name="btnControl" value="Accept">
<input type="submit" name="btnControl" value="Cancel">
</form>
</td>
</tr>
</table>
</section>
</body>
</html>
\ No newline at end of file
<%@page import="org.perpustakaan.models.*"%>
<%@ page language="java" contentType="text/html; charset=UTF-8"
pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
<title>User</title>
</head>
<body>
<section class="user">
<p>Hello <%=session.getAttribute("username") %></p>
<form action="controller.servlet" method="get">
<input type="submit" name="btnControl" value="logout">
</form>
</section>
<% Buku b = Autentifikasi.buku;%>
<section class="data">
<table>
<tr>
<th>ID</th>
<th>Judul</th>
<th>Status</th>
<th>Option</th>
</tr>
<tr>
<td><%= b.getId()%></td>
<td><%= b.getJudul()%></td>
<td><%= b.getStatus()%></td>
<td>
<form action="controller.servlet" method="post">
<input type="submit" name="btnControl" value="Request">
</form>
</td>
</tr>
</table>
</section>
</body>
</html>
\ No newline at end of file
package org.perpustakaan.controller;
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;
import javax.servlet.http.HttpSession;
import org.perpustakaan.models.Autentifikasi;
@WebServlet("/controller.servlet")
public class ControllerServlet extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public ControllerServlet() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doGet(HttpServletRequest request, HttpServletResponse response)
*/
protected void doGet(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
HttpSession session = request.getSession();
session.invalidate();
response.sendRedirect("login.jsp");
return;
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException
{
String status = request.getParameter("btnControl");
if(status.equalsIgnoreCase("accept"))
{
Autentifikasi.buku.setStatus("Pinjam");
response.sendRedirect("viewAdmin.jsp");
}else if(status.equalsIgnoreCase("cancel"))
{
Autentifikasi.buku.setStatus("Cancel");
response.sendRedirect("viewAdmin.jsp");
}else if(status.equalsIgnoreCase("request"))
{
Autentifikasi.buku.setStatus("request");
response.sendRedirect("viewUser.jsp");
}
}
}
package org.perpustakaan.controller;
import java.io.IOException;
import javax.servlet.RequestDispatcher;
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;
import org.perpustakaan.models.Autentifikasi;
@WebServlet("/login.do")
public class LoginController extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public LoginController() {
super();
// TODO Auto-generated constructor stub
}
/**
* @see HttpServlet#doPost(HttpServletRequest request, HttpServletResponse response)
*/
protected void doPost(HttpServletRequest request, HttpServletResponse response) throws ServletException, IOException {
String username = request.getParameter("username");
String password = request.getParameter("password");
HttpSession session = null;
RequestDispatcher dispatcher;
int role = Autentifikasi.isUserEksis(username, password);
if(role>-1)
{
session = request.getSession();
session.setAttribute("username", username);
if(role == 0)
{
//menampilkan view untuk admin
dispatcher = request.getRequestDispatcher("viewAdmin.jsp");
dispatcher.forward(request, response);
}else if(role == 1)
{
//menampilkan view untuk anggota
dispatcher = request.getRequestDispatcher("viewUser.jsp");
dispatcher.forward(request, response);
}
}else
{
//menampilkan view jika login gagal
dispatcher = request.getRequestDispatcher("loginFailed.jsp");
dispatcher.forward(request, response);
}
}
}
package org.perpustakaan.models;
import java.util.ArrayList;
import java.util.List;
public class Autentifikasi
{
public static List<User> users;
public static Buku buku;
static
{
users = new ArrayList<>();
buku = new Buku("SISOP", "Tersedia", 1);
users.add(new User("admin", "admin", 0));
users.add(new User("hottua", "hottua", 1));
}
public static int isUserEksis(String username, String password)
{
for(User u : users)
{
if(u.getUsername().equalsIgnoreCase(username) && u.getPassword().equalsIgnoreCase(password))
{
return u.getRole();
}
}
return -1;
}
}
package org.perpustakaan.models;
public class Buku
{
private String judul, status;
private int id;
public Buku(String judul, String status, int id) {
super();
this.judul = judul;
this.status = status;
this.id = id;
}
public String getJudul() {
return judul;
}
public void setJudul(String judul) {
this.judul = judul;
}
public String getStatus() {
return status;
}
public void setStatus(String status) {
this.status = status;
}
public int getId() {
return id;
}
public void setId(int id) {
this.id = id;
}
}
package org.perpustakaan.models;
public class User
{
private String username, password;
private int role;
public User(String username, String password, int role)
{
super();
this.username = username;
this.password = password;
this.role = role;
}
public String getPassword() {
return password;
}
public void setPassword(String password) {
this.password = password;
}
public int getRole() {
return role;
}
public void setRole(int role) {
this.role = role;
}
public String getUsername() {
return username;
}
public void setUsername(String username) {
this.username = username;
}
}
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