I'm making a mock up of an online store for school. I'm storing my products in an SQL Database. I want to display all products in the DB with buttons next to them that will send their ID to the cart_servlet. In order to display the products I'm generating a table like so:
public static String getInventory(){
String result = "<table>";
for ( Product p : DAO_Product.getProducts() ) {
result = result + "<tr>"
+ "<td>" + p.getName() + "</td>"
+ "<td><img src=\"resources/images/" + p.getImage() + "\" alt=\"Duke waving his hand\"></td>"
+ "<td>" + p.getDollars() + "</td>"
+ "<td>" + p.getPennies() + "</td>"
+ "<td>" + p.getStock() + "</td>"
+ "<td>" + p.getDescription() + "</td>"
//creates a form consisting of one button and a hidden value
//clicking the button should submit the corresponding hidden value
+ "<td><form action=\"${pageContext.request.contextPath}/cart_servlet\" method=\"post\">"
+ "<input type=\"hidden\" name=\"product\" value=\"" + p.getId() + "\" />"
+ "<input type=\"submit\" name=\"submit\" value=\"Add to Cart\" />"
+ "</form>"
//End Form
+ "</tr>";
}
}
This creates the correct table as I envisioned and the HTML it generates looks correct:

<table><tr><td>Caverna</td>
<td><img src="resources/images/caverna.jpg" alt="sampleImage"></td>
<td>112</td><td>12</td><td>34</td>
<td> you are the bearded leader of a small dwarf family which lives in a little cave in the mountains. Together, you</td>
<td><form action ="${pageContext.request.contextPath}/cart_servlet" method="post">
<input type="hidden" name="product" value="4" />
<input type="submit" name="submit" value="Add to Cart" />
</form>
However when I click the button I am presented with: 'HTTP Status 404 - Not Found' description: 'The requested resource is not available'
The Servlet I am requesting is my 'CartServlet':
@WebServlet( "/cart_servlet" )
public class CartServlet extends HttpServlet{
@Override
protected void doPost(HttpServletRequest req, HttpServletResponse resp) throws ServletException, IOException {
String result;
Status status = new Status();
req.setAttribute( "status", status );
//RequestDispatcher view = req.getRequestDispatcher( "browseProducts.jsp" );
if ( req.getParameter( "submit" ) != null ) {
}
//view.forward( req, resp );
}
}
I've commenting out everything in my 'CartServlet' and I am sure that it probably cant get the context somehow or find the class but I am unsure about how to fix this.