Commit 935efd41 by Ayu

Ini tugas Servlet_JSP_Perpustakaan

parents
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry kind="src" path="src"/>
<classpathentry kind="con" path="org.eclipse.jdt.launching.JRE_CONTAINER/org.eclipse.jdt.internal.debug.ui.launcher.StandardVMType/jre1.8.0_31">
<attributes>
<attribute name="owner.project.facets" value="java"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.server.core.container/org.eclipse.jst.server.tomcat.runtimeTarget/Apache Tomcat v9.0 (2)">
<attributes>
<attribute name="owner.project.facets" value="jst.web"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/>
<classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.module.container"/>
<classpathentry kind="output" path="build/classes"/>
</classpath>
<?xml version="1.0" encoding="UTF-8"?>
<projectDescription>
<name>Perpus</name>
<comment></comment>
<projects>
</projects>
<buildSpec>
<buildCommand>
<name>org.eclipse.jdt.core.javabuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.common.project.facet.core.builder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.jboss.tools.jst.web.kb.kbbuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.jboss.tools.cdi.core.cdibuilder</name>
<arguments>
</arguments>
</buildCommand>
<buildCommand>
<name>org.eclipse.wst.validation.validationbuilder</name>
<arguments>
</arguments>
</buildCommand>
</buildSpec>
<natures>
<nature>org.eclipse.jem.workbench.JavaEMFNature</nature>
<nature>org.eclipse.wst.common.modulecore.ModuleCoreNature</nature>
<nature>org.eclipse.wst.common.project.facet.core.nature</nature>
<nature>org.eclipse.jdt.core.javanature</nature>
<nature>org.jboss.tools.jst.web.kb.kbnature</nature>
<nature>org.jboss.tools.cdi.core.cdinature</nature>
<nature>org.eclipse.wst.jsdt.core.jsNature</nature>
</natures>
</projectDescription>
<?xml version="1.0" encoding="UTF-8"?>
<classpath>
<classpathentry excluding="**/bower_components/*|**/node_modules/*|**/*.min.js" kind="src" path="WebContent"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.JRE_CONTAINER"/>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.WebProject">
<attributes>
<attribute name="hide" value="true"/>
</attributes>
</classpathentry>
<classpathentry kind="con" path="org.eclipse.wst.jsdt.launching.baseBrowserLibrary"/>
<classpathentry kind="output" path=""/>
</classpath>
eclipse.preferences.version=1
org.eclipse.jdt.core.compiler.codegen.inlineJsrBytecode=enabled
org.eclipse.jdt.core.compiler.codegen.targetPlatform=1.8
org.eclipse.jdt.core.compiler.compliance=1.8
org.eclipse.jdt.core.compiler.problem.assertIdentifier=error
org.eclipse.jdt.core.compiler.problem.enumIdentifier=error
org.eclipse.jdt.core.compiler.source=1.8
<?xml version="1.0" encoding="UTF-8"?><project-modules id="moduleCoreId" project-version="1.5.0">
<wb-module deploy-name="Perpus">
<wb-resource deploy-path="/" source-path="/WebContent" tag="defaultRootSource"/>
<wb-resource deploy-path="/WEB-INF/classes" source-path="/src"/>
<property name="java-output-path" value="/Perpus/build/classes"/>
<property name="context-root" value="Perpus"/>
</wb-module>
</project-modules>
<?xml version="1.0" encoding="UTF-8"?>
<faceted-project>
<runtime name="Apache Tomcat v9.0 (2)"/>
<fixed facet="wst.jsdt.web"/>
<fixed facet="jst.web"/>
<fixed facet="java"/>
<installed facet="java" version="1.8"/>
<installed facet="jst.web" version="3.1"/>
<installed facet="wst.jsdt.web" version="1.0"/>
</faceted-project>
org.eclipse.wst.jsdt.launching.baseBrowserLibrary
\ No newline at end of file
eclipse.preferences.version=1
org.jboss.ide.eclipse.as.core.singledeployable.deployableList=
{
"plugins": {
"guess-types": {
},
"outline": {
},
"angular": {
}
},
"libs": [
"ecma5",
"browser"
]
}
\ No newline at end of file
<%@page import="org.perpus.model.*"%>
<html>
<head>
<title>Perpustakaan</title>
</head>
<body>
<header>
Perpustakaan
</header>
<nav>
<a href="/Perpus/Home.jsp">Home</a>
<a href="/Perpus/DaftarBuku.jsp">Daftar Buku</a>
<% if(session.getAttribute("username")!=null) {%>
<a href="/Perpus/LogOut.do">Logout</a>
<%}else {%>
<a href="/Perpus/Login.jsp">Login</a>
<%} %>
</nav>
<table border="1">
<tr>
<th>Judul</th>
<th>ISBN</th>
<th>Deskripsi</th>
<th>Letak</th>
<th>Penerbit</th>
<th>Penulis</th>
<th>Tahun</th>
<th>Jumlah</th>
</tr>
<% for(Buku buku : ListBuku.getBukus()){%>
<tr>
<td> <% out.print(buku.getJudul()); %></td>
<td> <% out.print(buku.getIsbn()); %></td>
<td> <% out.print(buku.getDeskripsi()); %></td>
<td> <% out.print(buku.getLetak()); %></td>
<td> <% out.print(buku.getPenerbit()); %></td>
<td> <% out.print(buku.getPengarang()); %></td>
<td> <% out.print(buku.getTahun()); %></td>
<td> <% out.print(buku.getJumlah()); %></td>
</tr>
<%} %>
</table>
</body>
</html>
\ No newline at end of file
<html>
<head>
<title>Perpustakaan</title>
</head>
<body>
<header>
Perpustakaan
</header>
<nav>
<a href="/Perpus/Home.jsp">Home</a>
<a href="/Perpus/DaftarBuku.jsp">Daftar Buku</a>
<% if(session.getAttribute("username")!=null) {%>
<a href="/Perpus/LogOut.do">Logout</a>
<%}else {%>
<a href="/Perpus/Login.jsp">Login</a>
<%} %>
</nav>
<h1>Perpustakaan IT Del</h1>
<p>
Selamat datang di perpustakaan IT Del
</p>
</body>
</html>
\ No newline at end of file
<html>
<head>
<title>Perpustakaan</title>
</head>
<body>
<header>
Perpustakaan
</header>
<nav>
<a href="/Perpus/Home.jsp">Home</a>
<a href="/Perpus/DaftarBuku.jsp">Daftar Buku</a>
<% if(session.getAttribute("username")!=null) {%>
<a href="/Perpus/LogOut.do">LogOut</a>
<%}else {%>
<a href="/Perpus/Login.jsp">Login</a>
<%} %>
</nav>
<form action="/Perpus/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"><input type="submit" name="submit" value="login"></td>
</tr>
</table>
</form>
</body>
</html>
\ No newline at end of file
Manifest-Version: 1.0
Class-Path:
package org.perpus.model;
public class Buku
{
private String isbn, judul, deskripsi, letak, penerbit, pengarang;
private Integer tahun, jumlah;
public Buku()
{
super();
}
public Buku(String isbn, String judul, String deskripsi, String letak, String penerbit, String pengarang, Integer tahun, Integer jumlah)
{
super();
this.isbn = isbn;
this.judul = judul;
this.deskripsi = deskripsi;
this.letak = letak;
this.penerbit = penerbit;
this.pengarang = pengarang;
this.tahun = tahun;
this.pengarang = pengarang;
this.tahun = tahun;
this.jumlah = jumlah;
}
public String getIsbn()
{
return isbn;
}
public void setIsbn(String isbn)
{
this.isbn = isbn;
}
public String getJudul()
{
return judul;
}
public void setJudul(String judul)
{
this.judul = judul;
}
public String getDeskripsi()
{
return deskripsi;
}
public void setDeskripsi(String deskripsi)
{
this.deskripsi = deskripsi;
}
public String getLetak()
{
return letak;
}
public void setLetak(String letak)
{
this.letak = letak;
}
public String getPenerbit()
{
return penerbit;
}
public void setPenerbit(String penerbit)
{
this.penerbit = penerbit;
}
public String getPengarang()
{
return pengarang;
}
public void setPengarang(String pengarang)
{
this.pengarang = pengarang;
}
public Integer getTahun()
{
return tahun;
}
public void setTahun(Integer tahun)
{
this.tahun = tahun;
}
public Integer getJumlah()
{
return jumlah;
}
public void setJumlah(Integer jumlah)
{
this.jumlah = jumlah;
}
}
\ No newline at end of file
package org.perpus.model;
import java.util.ArrayList;
import java.util.List;
public class ListBuku
{
private static List<Buku> bukus = new ArrayList<>();
static
{
bukus.add(new Buku("1234", "ayah", "ayah", "novel", "gramedia", "ali", 2015, 5));
bukus.add(new Buku("2345", "ibu", "ibu", "novel", "gramedia","momo", 2016, 7));
bukus.add(new Buku("3456", "toefl", "toefl", "school", "longman", "debora", 2004, 8));
bukus.add(new Buku("4567", "probability", "probability", "education", "itb", "joko", 1999, 5));
}
public static List<Buku> getBukus()
{
return bukus;
}
public static void setBukus(List<Buku> bukus)
{
ListBuku.bukus = bukus;
}
public static void addToListBukus(Buku buku)
{
ListBuku.bukus.add(buku);
}
public static Buku getBukuFromList(String judul)
{
for(Buku buku : ListBuku.bukus)
{
if(buku.getJudul().compareTo(judul) == 0)
{
return buku;
}
}
return null;
}
public static boolean isBukuExist(String judul)
{
for(Buku buku : bukus)
{
if(buku.getJudul().compareTo(judul) == 0 && buku.getJumlah() != 0)
{
return true;
}
}
return false;
}
}
package org.perpus.model;
import java.util.ArrayList;
import java.util.List;
public class ListPeminjaman
{
private static List<Peminjaman> peminjamans = new ArrayList<>();
public static List<Peminjaman> getPeminjamans()
{
return peminjamans;
}
public static void setPeminjamans(List<Peminjaman> peminjamans)
{
ListPeminjaman.peminjamans = peminjamans;
}
public static void addToListPeminjamans(String username, String judul)
{
Buku buku = ListBuku.getBukuFromList(judul);
if(buku == null || buku.getJumlah()==0)
{
return;
}
else
{
Peminjaman peminjaman = new Peminjaman(username,judul,"pending");
ListPeminjaman.peminjamans.add(peminjaman);
buku.setJumlah(buku.getJumlah()-1);
}
}
public static Peminjaman getPeminjamanFromList(String username, String judul)
{
Buku buku = ListBuku.getBukuFromList(judul);
if(buku == null || buku.getJumlah() == 0)
{
return null;
}
else
{
for(Peminjaman peminjaman : ListPeminjaman.peminjamans)
{
if(peminjaman.getUsername().compareTo(username) == 0
&& peminjaman.getJudul().compareTo(judul) == 0)
{
return peminjaman;
}
}
return null;
}
}
public static void deletePeminjaman(String username, String judul)
{
Peminjaman peminjaman = ListPeminjaman.getPeminjamanFromList(username, judul);
if(peminjaman==null)
{
return;
}
else
{
ListPeminjaman.peminjamans.remove(peminjaman);
Buku buku = ListBuku.getBukuFromList(judul);
buku.setJumlah(buku.getJumlah()+1);
}
}
public static boolean isPeminjamanExist(String username, String judul)
{
for(Peminjaman peminjaman : peminjamans)
{
if(peminjaman.getUsername().compareTo(username) == 0 && peminjaman.getJudul().compareTo(judul) == 0){
return true;
}
}
return false;
}
public static void changeStatusPeminjaman(String username,String judul,String status)
{
Peminjaman peminjaman = getPeminjamanFromList(username, judul);
peminjaman.setStatus(status);
}
}
package org.perpus.model;
import java.util.ArrayList;
import java.util.List;
public class ListUser
{
private static List<User> users = new ArrayList<>();
static
{
users.add(new User("root", "root", "123","admin"));
users.add(new User("aan", "aan", "234", "user"));
users.add(new User("ani", "ani", "345", "user"));
users.add(new User("adi", "adi", "456", "user"));
}
public static List<User> getUsers()
{
return users;
}
public static void setUsers(List<User> users)
{
ListUser.users = users;
}
public static void addToListUsers(User user)
{
ListUser.users.add(user);
}
public static User getUserFromList(String username)
{
for(User user : ListUser.users)
{
if(user.getUsername().compareTo(username) == 0)
{
return user;
}
}
return null;
}
public static boolean isUserExist(String username, String password)
{
for(User user : ListUser.users)
{
if(user.getUsername().compareTo(username) == 0 && user.getPassword().compareTo(password) == 0)
{
return true;
}
}
return false;
}
}
package org.perpus.model;
public class Peminjaman
{
String username,judul,status;
public Peminjaman()
{
super();
}
public Peminjaman(String username, String judul,String status)
{
super();
this.username = username;
this.judul = judul;
this.status = status;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
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;
}
}
package org.perpus.model;
public class User
{
private String username, password, nim, role;
public User()
{
super();
}
public User(String username, String password, String nim, String role)
{
super();
this.username = username;
this.password = password;
this.nim = nim;
this.role = role;
}
public String getUsername()
{
return username;
}
public void setUsername(String username)
{
this.username = username;
}
public String getPassword()
{
return password;
}
public void setPassword(String password)
{
this.password = password;
}
public String getNim()
{
return nim;
}
public void setNim(String nim)
{
this.nim = nim;
}
public String getRole()
{
return role;
}
public void setRole(String role)
{
this.role = role;
}
}
package org.perpus.page;
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;
/**
* Servlet implementation class LogOut
*/
@WebServlet("/LogOut.do")
public class LogOut extends HttpServlet {
private static final long serialVersionUID = 1L;
/**
* @see HttpServlet#HttpServlet()
*/
public LogOut() {
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("/Perpus/Home.jsp");
//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 {
HttpSession session = request.getSession();
session.invalidate();
response.sendRedirect("/Perpus/Home.jsp");
//doGet(request, response);
}
}
package org.perpus.page;
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;
import org.perpus.model.ListUser;
import org.perpus.model.User;
/**
* Servlet implementation class Login
*/
@WebServlet("/Login.do")
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 {
response.setContentType("text/html");
PrintWriter pw = response.getWriter();
String userInput = request.getParameter("username");
String passwordInput = request.getParameter("password");
if(ListUser.isUserExist(userInput, passwordInput)){
User user = ListUser.getUserFromList(userInput);
HttpSession session = request.getSession();
session.setAttribute("username", user.getUsername());
session.setAttribute("role", user.getRole());
response.sendRedirect("/Perpus/Home.jsp");
}
else{
response.sendRedirect("/Perpus/Login.jsp");
}
//pw.println("<html><head></head><body><H1>Redirect diterima.. </H1></body></html>");
//doGet(request, response);
}
}
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