-
Notifications
You must be signed in to change notification settings - Fork 3
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
- Loading branch information
Showing
15 changed files
with
344 additions
and
21 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,96 @@ | ||
<%@ page language="java" contentType="text/html; charset=UTF-8" | ||
pageEncoding="UTF-8"%> | ||
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Rent It All Items</title> | ||
</head> | ||
|
||
<body> | ||
<h1 style="text-align:center;">Items Management</h1> | ||
<h2 style="text-align:center;"> | ||
<a href="/new">Add New Item</a> | ||
| ||
<a href="/list">List All Items</a> | ||
|
||
</h2> | ||
|
||
<div align="center"> | ||
<c:if test="${ITEMS != null}"> | ||
<form action="update" method="post"> | ||
</c:if> | ||
<c:if test="${ITEMS == null}"> | ||
<form action="insert" method="post"> | ||
</c:if> | ||
|
||
<table border="1"> | ||
<caption> | ||
<h2> | ||
<c:if test="${ITEMS != null}"> | ||
Edit Item | ||
</c:if> | ||
<c:if test="${ITEMS == null}"> | ||
Add New Item | ||
</c:if> | ||
</h2> | ||
</caption> | ||
<c:if test="${ITEMS != null}"> | ||
<input type="hidden" name="id" value="<c:out value='${ITEMS.ID}' />" /> | ||
</c:if> | ||
<tr> | ||
<th>Name: </th> | ||
<td> | ||
<input type="text" name="name" size="45" | ||
value="<c:out value='${ITEMS.Name}' />" | ||
/> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th>Category: </th> | ||
<td> | ||
<input type="text" name="category" size="45" | ||
value="<c:out value='${ITEMS.Category}' />" | ||
/> | ||
</td> | ||
</tr> | ||
<tr> | ||
<th>Price: </th> | ||
<td> | ||
<input type="text" name="price" size="5" | ||
value="<c:out value='${ITEMS.PricePerDay}' />" | ||
/> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<th>Duration: </th> | ||
<td> | ||
<input type="text" name="duration" size="5" | ||
value="<c:out value='${ITEMS.Duration}' />" | ||
/> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<th>Security Deposit: </th> | ||
<td> | ||
<input type="text" name="deposit" size="5" | ||
value="<c:out value='${ITEMS.SecurityDepo}' />" | ||
/> | ||
</td> | ||
</tr> | ||
|
||
<tr> | ||
<td colspan="2" align="center"> | ||
<input type="submit" value="Save" /> | ||
</td> | ||
</tr> | ||
</table> | ||
</form> | ||
</div> | ||
</body> | ||
</html> |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,56 @@ | ||
<%@ page language="java" contentType="text/html; charset=UTF-8" | ||
pageEncoding="UTF-8"%> | ||
<%@ taglib prefix = "c" uri = "http://java.sun.com/jsp/jstl/core" %> | ||
|
||
<!DOCTYPE html> | ||
<html> | ||
|
||
<head> | ||
<meta charset="UTF-8"> | ||
<title>Rent It All Items</title> | ||
</head> | ||
|
||
<body> | ||
|
||
<h1 style="text-align:center;"> ITEMS FOR RENTING </h1> | ||
<h2 style="text-align:center;"> | ||
<a href="/new">Add New Item</a> | ||
| ||
<a href="/list">List All Items</a> | ||
</h2> | ||
|
||
<div align="center"> | ||
<table border="1"> | ||
<caption> | ||
List of Items | ||
</caption> | ||
<tr> | ||
<th>ID</th> | ||
<th>Name</th> | ||
<th>Category</th> | ||
<th>Price</th> | ||
<th>Duration</th> | ||
<th>Security Deposit </th> | ||
<th>Actions</th> | ||
</tr> | ||
|
||
<c:forEach var="ITEMS" items="${listItem}"> | ||
<tr> | ||
<td><c:out value="${ITEMS.ID}" /></td> | ||
<td><c:out value="${ITEMS.Name}" /></td> | ||
<td><c:out value="${ITEMS.Category}" /></td> | ||
<td><c:out value="${ITEMS.PricePerDay}" /></td> | ||
<td><c:out value="${ITEMS.Duration}" /></td> | ||
<td><c:out value="${ITEMS.SecurityDepo}" /></td> | ||
<td> | ||
<a href="/edit?ID=<c:out value='${ITEMS.ID}' />">Edit</a> | ||
| ||
<a href="/delete?id=<c:out value='${ITEMS.ID}' />">Delete</a> | ||
</td> | ||
</tr> | ||
</c:forEach> | ||
</table> | ||
</div> | ||
|
||
</body> | ||
</html> |
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,120 @@ | ||
package items; | ||
|
||
import java.io.IOException; | ||
import java.sql.SQLException; | ||
import java.util.List; | ||
|
||
import javax.servlet.GenericServlet; | ||
import javax.servlet.RequestDispatcher; | ||
import javax.servlet.ServletException; | ||
import javax.servlet.http.HttpServlet; | ||
import javax.servlet.http.HttpServletRequest; | ||
import javax.servlet.http.HttpServletResponse; | ||
|
||
|
||
public class ControllerServlet extends HttpServlet { | ||
private static final long serialVersionUID = 1L; | ||
private ItemDBC itemDBC; | ||
|
||
public void init() { | ||
String jdbcURL = getServletContext().getInitParameter("jdbcURL"); | ||
String jdbcUsername = getServletContext().getInitParameter("jdbcUsername"); | ||
String jdbcPassword = getServletContext().getInitParameter("jdbcPassword"); | ||
|
||
itemDBC = new ItemDBC(jdbcURL, jdbcUsername, jdbcPassword); | ||
} | ||
|
||
protected void doPost(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
doGet(request, response); | ||
} | ||
|
||
protected void doGet(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
String action = request.getServletPath(); | ||
|
||
try { | ||
switch (action) { | ||
case "/new": | ||
showNewForm(request, response); | ||
break; | ||
case "/insert": | ||
insertItem(request, response); | ||
break; | ||
case "/delete": | ||
deleteItem(request, response); | ||
break; | ||
case "/edit": | ||
showEditForm(request, response); | ||
break; | ||
case "/update": | ||
updateItem(request, response); | ||
break; | ||
default: | ||
listItem(request, response); | ||
break; | ||
} | ||
} catch (SQLException ex) { | ||
throw new ServletException(ex); | ||
} | ||
} | ||
|
||
private void listItem(HttpServletRequest request, HttpServletResponse response) | ||
throws SQLException, IOException, ServletException { | ||
List<Item> listItem = ItemDBC.listAllItems(); | ||
request.setAttribute("listItem", listItem); | ||
RequestDispatcher dispatcher = request.getRequestDispatcher("ItemList.jsp"); | ||
dispatcher.forward(request, response); | ||
} | ||
|
||
private void showNewForm(HttpServletRequest request, HttpServletResponse response) | ||
throws ServletException, IOException { | ||
RequestDispatcher dispatcher = request.getRequestDispatcher("ItemForm.jsp"); | ||
dispatcher.forward(request, response); | ||
} | ||
|
||
private void showEditForm(HttpServletRequest request, HttpServletResponse response) | ||
throws SQLException, ServletException, IOException { | ||
int id = Integer.parseInt(request.getParameter("ID")); | ||
Item existingItem = ItemDBC.getItem(id); | ||
RequestDispatcher dispatcher = request.getRequestDispatcher("ItemForm.jsp"); | ||
request.setAttribute("item", existingItem); | ||
dispatcher.forward(request, response); | ||
} | ||
|
||
private void insertItem(HttpServletRequest request, HttpServletResponse response) | ||
throws SQLException, IOException { | ||
String name = request.getParameter("Name"); | ||
String category = request.getParameter("category"); | ||
int price = Integer.parseInt(request.getParameter("PricePerDay")); | ||
int duration = Integer.parseInt(request.getParameter("Duration")); | ||
int deposit = Integer.parseInt(request.getParameter("SecurityDepo")); | ||
|
||
Item newItem = new Item(name, category, price, duration, deposit); | ||
ItemDBC.insertItem(newItem); | ||
response.sendRedirect("list"); | ||
} | ||
|
||
private void updateItem(HttpServletRequest request, HttpServletResponse response) | ||
throws SQLException, IOException { | ||
int id = Integer.parseInt(request.getParameter("ID")); | ||
String name = request.getParameter("Name"); | ||
String category = request.getParameter("Category"); | ||
int price = Integer.parseInt(request.getParameter("PricePerDay")); | ||
int duration = Integer.parseInt(request.getParameter("Duration")); | ||
int deposit = Integer.parseInt(request.getParameter("SecurityDepo")); | ||
|
||
Item item = new Item(id, name, category, price, duration, deposit); | ||
ItemDBC.updateItem(item); | ||
response.sendRedirect("list"); | ||
} | ||
|
||
private void deleteItem(HttpServletRequest request, HttpServletResponse response) | ||
throws SQLException, IOException { | ||
int id = Integer.parseInt(request.getParameter("ID")); | ||
|
||
Item item = new Item(id); | ||
ItemDBC.deleteItem(item); | ||
response.sendRedirect("list"); | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.