(Solved) : Really Need Help Adding Code Advanced Java Programming Class Uses Java Servets Jsp Done Ja Q42789465 . . .

I really need help with adding some code in this is for myAdvanced Java Programming class that uses Java Servets and JSP.This is all done in Java. I will post code that I was told toopen.

Exercise 18-2: Enhance the library checkout system to use”pretty” URLs

In this exercise, you’ll use the request header to enhance thelibrary checkout system so it uses more readable URLs instead ofaction parameters and hidden action fields. You’ll also enhance theapplication by adding default response handlers to the switchstatements.

Review the project

  • Start NetBeans and open the project named ch18_ex2_librarythat’s in the more_ex_starts directory.
  • Open the web.xml file and note that the controller servlet isnow mapped to all subdirectories of the goldenoaksdirectory.
  • Open the index.jsp file and note that the links now uses theend of the URL instead of an action parameter. For example:

goldenoaks?action=checkout
has been changed to
goldenoaks/checkout

  • Open the checkout.jsp and checkedOutList.jsp files and notethat the form action has been changed to specify the correct actionand that the hidden action has been removed.
  • Note that the index.jsp and checkout.jsp files call the sameURL. However, they perform different actions. This is possiblebecause index.jsp makes a GET request, and checkout.jsp makes aPOST request. As a result, they call different methods in thecontroller.

Modify the code

  • Open the web.xml file and modify theurl-pattern so that the LibraryController class handles requests toany subdirectories of goldenoaks. Hint You can use the * as awildcard operator.
  • Open the LibraryController class.
  • In the doGet method, modify the code to the path info from therequest to obtain the action instead of the using the actionparameter. You can refer to figure 18-11 in the book as areference.
  • Repeat step 2 for the doPost method. Make sure to change thestrings in the switch statement so they’re correct.
  • Add a default clause at the end of the switchstatement in the doPost and doGetmethods that sends a 404 error to the user if none of the requestedURL’s match any of the known URL’s in the app.

Run the application

  • Run the application and verify that it still works correctly.Note that the URLs are cleaner and easier to read.

web.xml

<?xml version=”1.0″ encoding=”UTF-8″?>
<web-app version=”3.1″xsi:schemaLocation=”http://;
switch (action) {
case “checkout”:
url = “/checkout.jsp”;
break;
case “manage”:
url = manage(request, response);
break;
}

getServletContext().getRequestDispatcher(url)
.forward(request, response);
}

@Override
public void doPost(HttpServletRequest request,
HttpServletResponse response)
throws ServletException, IOException {
String action = request.getParameter(“action”);
String url = “”;
switch (action) {
case “doCheckout”:
url = doCheckout(request, response);
break;
case “doCheckin”:
url = doCheckin(request, response);
break;
}

getServletContext().getRequestDispatcher(url)
.forward(request, response);
}

private String manage(HttpServletRequest request,
HttpServletResponse response) {
List checkedOutList = CheckoutDb.selectCheckedOutBooks();
request.setAttribute(“checkedOutList”, checkedOutList);
return “/checkedOutList.jsp”;
}

private String doCheckout(HttpServletRequest request,
HttpServletResponse response) {
Checkout checkout = new Checkout();
checkout.setFirstName(request.getParameter(“firstName”));
checkout.setLastName(request.getParameter(“lastName”));
checkout.setEmailAddress(request.getParameter(“emailAddress”));
checkout.setBookTitle(request.getParameter(“bookTitle”));

CheckoutDb.checkoutBook(checkout);
request.setAttribute(“checkout”, checkout);

return “/thankyou.jsp”;
}

private String doCheckin(HttpServletRequest request,
HttpServletResponse response) {
long checkoutNumber =
Long.parseLong(request.getParameter(“checkoutNumber”));
CheckoutDb.checkinBook(checkoutNumber);
return manage(request, response);
}
}

index.jsp

<%@include file=”includes/header.jsp” %>
<section>
<a href=”goldenoaks/checkout”>Check out abook</a><br>
<a href=”goldenoaks/manage”>Manage checked outbooks</a>
</section>
</body>
</html>

checkout.jsp

<%@include file=”includes/header.jsp” %>
<section>
<h1>Checkout a book</h1>
<form action=”checkout” method=”post”>
<input type=”hidden” name=”action” value=”doCheckout”/>
<label>First Name:</label>
<input type=”text” name=”firstName”
value=”${checkout.firstName}” required/><br>
<label>Last Name:</label>
<input type=”text” name=”lastName”
value=”${checkout.lastName}” required/><br>
<label>Email Address:</label>
<input type=”text” name=”emailAddress”
value=”${checkout.emailAddress}” required/><br>
<label>Book Title:</label>
<input type=”text” name=”bookTitle” class=”title”
value=”${checkout.bookTitle}” required/><br>
<label>&nbsp;</label>
<input type=”submit” value=”Checkout”/><br>
</form>
</section>
</body>
</html>

checkedOutList.jsp

<%@include file=”includes/header.jsp” %>
<%@ taglib prefix=”c” uri=”http://java.sun.com/jsp/jstl/core”%>
<section class=”checkedOut”>
<h1>Currently checked out books</h1>
<table>
<tr>
<th>Patron Name</th>
<th>Email Address</th>
<th>Book Title</th>
<th>Due Date</th>
<th>Overdue</th>
</tr>
<c:forEach var=”checkout” items=”${checkedOutList}”>
<tr>
<td>${checkout.firstName}${checkout.lastName}</td>
<td>${checkout.emailAddress}</td>
<td>${checkout.bookTitle}</td>
<td>${checkout.formattedDate}</td>
<c:choose>
<c:when test=”${checkout.overdue}”>
<td class=”overdue”><img src=”<c:urlvalue=’/images/overdue.png’/>”/></td>
</c:when>
<c:otherwise>
<td class=”overdue”>&nbsp;</td>
</c:otherwise>
</c:choose>
<td>&nbsp;</td>
<td>
<form action=”checkin” method=”post”>
<input type=”hidden” name=”checkoutNumber”
value=”${checkout.checkoutNumber}”/>
<input type=”submit” value=”Check in”/>
</form>
</td>
</tr>
</c:forEach>
</table>
<p><a href=”<c:url value=’/’/>”>Return to frontpage</a></p>
</section>
</body>
</html>

Please if an expert can help me I would appreciate it! Thankyou!

Expert Answer


Answer to I really need help with adding some code in this is for my Advanced Java Programming class that uses Java Servets and JS…

Leave a Comment

About

We are the best freelance writing portal. Looking for online writing, editing or proofreading jobs? We have plenty of writing assignments to handle.

Quick Links

Browse Solutions

Place Order

About Us