(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:

has been changed to

  • 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.


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

.forward(request, response);

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);
case “doCheckin”:
url = doCheckin(request, response);

.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();

request.setAttribute(“checkout”, checkout);

return “/thankyou.jsp”;

private String doCheckin(HttpServletRequest request,
HttpServletResponse response) {
long checkoutNumber =
return manage(request, response);


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


<%@include file=”includes/header.jsp” %>
<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>
<input type=”submit” value=”Checkout”/><br>


<%@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>
<th>Patron Name</th>
<th>Email Address</th>
<th>Book Title</th>
<th>Due Date</th>
<c:forEach var=”checkout” items=”${checkedOutList}”>
<c:when test=”${checkout.overdue}”>
<td class=”overdue”><img src=”<c:urlvalue=’/images/overdue.png’/>”/></td>
<td class=”overdue”>&nbsp;</td>
<form action=”checkin” method=”post”>
<input type=”hidden” name=”checkoutNumber”
<input type=”submit” value=”Check in”/>
<p><a href=”<c:url value=’/’/>”>Return to frontpage</a></p>

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


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