-
Notifications
You must be signed in to change notification settings - Fork 3
New issue
Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.
By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.
Already on GitHub? Sign in to your account
Items table func #15
Open
sonalsk
wants to merge
2
commits into
WooTechnology:master
Choose a base branch
from
sonalsk:ItemsTableFunc
base: master
Could not load branches
Branch not found: {{ refName }}
Loading
Could not load tags
Nothing to show
Loading
Are you sure you want to change the base?
Some commits from the old base branch may be removed from the timeline,
and old review comments may become outdated.
Open
Items table func #15
Changes from all commits
Commits
Show all changes
2 commits
Select commit
Hold shift + click to select a range
File filter
Filter by extension
Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
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.
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(); | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. Create a session variable on your JSP instead and just get the value from that page. |
||
|
||
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"); | ||
} | ||
} |
Oops, something went wrong.
Add this suggestion to a batch that can be applied as a single commit.
This suggestion is invalid because no changes were made to the code.
Suggestions cannot be applied while the pull request is closed.
Suggestions cannot be applied while viewing a subset of changes.
Only one suggestion per line can be applied in a batch.
Add this suggestion to a batch that can be applied as a single commit.
Applying suggestions on deleted lines is not supported.
You must change the existing code in this line in order to create a valid suggestion.
Outdated suggestions cannot be applied.
This suggestion has been applied or marked resolved.
Suggestions cannot be applied from pending reviews.
Suggestions cannot be applied on multi-line comments.
Suggestions cannot be applied while the pull request is queued to merge.
Suggestion cannot be applied right now. Please check back later.
There was a problem hiding this comment.
Choose a reason for hiding this comment
The reason will be displayed to describe this comment to others. Learn more.
Init is not needed. You can craete a default constructor of the servlet and call getConnection function
Connection con = itemDBC.getConnection();