I have set up Tomcat (TomEE)/7.0.62 (1.7.2) in Netbeans and the server runs fine. I added these jars in $CATALINA_HOME/lib:
- javaee-api-6.0-6.jar
- javax.servlet.jsp.jstl-1.2.1.jar
I have the proper configuration in context.xml and web.xml for accessing the database using JDBC for Mysql because i'm able to see the data with these JSTL tags:
<c:forEach var="cartItem" items="${cart.items}" varStatus="iter">
<c:set var="product" value="${cartItem.product}"/>
<div id="product_container_cart" class="lazyload">
<div class="product_img_container">
<div id="product_image"><a href="viewProduct?${product.id}">
<img class="cart_img" alt="" src="${initParam.productGalleryImagePath}${product.id} (1).jpg" /></a></div>
</div>
<div class="product_name_container">
<div style="text-align:center;" id="product_name"><a class="category_links" href="viewProduct?${product.id}">${product.name}</a></div>
</div>
<div class="product_price_container">
<div id="product_price" style="text-align:center;" >$${product.price}</div></div>
<div id="button_wrapper_cart">
<div id="add_toList_cart"><form id="wishlistFormCart" action="addToWishlist" method="post">
<input name="productId" value="${product.id}" type="hidden">
<input id="submit_list_cart" class="submit" value="<fmt:message key='AddToWishlist'/>" type="submit">
</form></div>
<div id="updateCart">
<form id="updateForm" action="updateCart" method="post">
<input type="hidden"
name="productId"
value="${product.id}">
<label for="quantity">Quantity</label>
<input type="text"
maxlength="2"
size="2"
value="${cartItem.quantity}"
name="quantity"
style="margin:0px">
<input class="updateButton" type="submit"
name="submit"
onclick="updatedCart()"
value="<fmt:message key='update'/>">
</form>
</div>
</div>
</div>
</c:forEach>
but with these tags, the data do NOT display:
<c:forEach var="product" items="${categoryProducts}" varStatus="iter">
<div id="product_container" class="lazyload">
<div class="product_img_container">
<div id="product_image"><a href="viewProduct?${product.id}">
<img class="img" alt="" src="${initParam.productGalleryImagePath}${product.id} (1).jpg" /></a></div>
</div>
<div class="product_name_container">
<div id="product_name"><a class="category_links" href="viewProduct?${product.id}">${product.name}</a></div>
</div>
<div class="product_price_container">
<div id="product_price">$${product.price}</div></div>
<div id="button_wrapper_category">
<div id="add_toList">
<form id="wishlistForm" action="addToWishlist" method="post">
<input name="productId" value="${product.id}" type="hidden">
<input id="submit_list" class="submit" value="<fmt:message key='AddToWishlist'/>" type="submit">
</form></div>
<div id="add_toCart">
<form id="cartForm" action="addToCart" method="post">
<input name="productId" value="${product.id}" type="hidden">
<input id="submit_cart" class="submit" value="<fmt:message key='AddToCart'/>" type="submit">
</form></div>
</div>
</div>
</c:forEach>
Any idea why? I tested the connection to the database by trying to display simple product ids with this:
<%@ page import="java.sql.*" %>
<% Connection connection = null;
Class.forName("com.mysql.jdbc.Driver").newInstance();
connection = DriverManager.getConnection("jdbc:mysql://localhost/<DATABASE NAME>?user=<USERNAME>&password=<PASSWORD>");
Statement sql = connection.createStatement();
ResultSet result = sql.executeQuery("SELECT product FROM category_has_product");
while(result.next() )
{
out.println(result.getString("product_id") + "<br />");
} %>
I was able to display all the product IDs which is a good sign that Tomcat can successfully connect to the DB and retrieve requested data. So what is the issue with the second tag?
The problem should be:
Check if you binding this variable categoryProducts to request object and it has content