views:

39

answers:

1

I'm having difficulty showing the model values from my controller to my JSP view. Everything works in Tomcat 6. But it doesn't work in Tomcat 5.5. Here are my files.

web.xml for Tomcat 5.5 (For Tomcat 6, I use version="2.5" and the correct schema)

<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://java.sun.com/xml/ns/j2ee"
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
    xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee 
    http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd"
    version="2.4">

Versions:

Tomcat: 5.5

Taglib: jstl.jar, standard.jar (1.1 version)

Controller

@Controller
@RequestMapping("/inventory")
public class SimpleController {

        @Autowired
        @Qualifier("inventoryService")
        private IInventoryService inventoryService;

        // Our default method when a simple GET request is made to /simple
        @SuppressWarnings("unchecked")
        @RequestMapping(method = RequestMethod.GET)
        public String viewProducts(ModelMap model) {
            List<IInventory> retrieved = inventoryService.getInventories();
            List <InventoryDTO> inventories = new ArrayList();

            for (IInventory inventory: retrieved) {
                InventoryDTO inventoryDTO= new InventoryDTO();
                inventoryDTO.setId(inventory.getId());
                inventoryDTO.setBrandName(inventory.getBrand().getName());
                inventories.add(inventoryDTO);
            }

            model.put ( "inventories", inventories );

            // This will resolve to a logical view name /WEB-INF/jsp/inventoriesView.jsp
            return "inventoriesView";
        }

}

inventoriesView.jsp

<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="form" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<html>
<head>
    <style type="text/css">
    <%@include file="../../resources/style.css" %>
    </style>
    <meta http-equiv="Content-Type" content="text/html; charset=UTF-8" />
<title>Inventories</title>
</head>
<body>
<h1>Inventory</h1>
<br/>
<%@include file="menu.jsp" %>
<br /><br />
<c:if test="${!empty inventories}" >
    <table class="table" border="1">
        <tr>
            <th>ID</th>
            <th>Brand</th>
        </tr>
        <c:forEach items="${inventories}" var="inventory">
        <tr>
            <td><c:out value="${inventory.id}" /></td>
            <td><c:out value="${inventory.brandName}" /></td>
        </tr>
        </c:forEach>
    </table>
</c:if>
<c:if test="${empty inventories}">
    There are currently no inventories.
</c:if>
</body>
</html>

Remember this works flawlessly in Tomcat 6.0, but not in Tomcat 5.5. I don't get any error. It just won't display the data as if the model is null. When I call an EL expression {2+2} I get 4 as the value both for Tomcat 5.5 and 6. Thanks

+1  A: 

I guess that you've a Tomcat 6 specific EL JAR file in your /WEB-INF/lib which caused -among others- the EL empty keyword to fail in Tomcat 5.5. Ensure that your /WEB-INF/lib is free of servletcontainer-specific libraries. I would also check the Tomcat 5.5 logs for any failures during startup and webapp initialization. Those will namely not per se be represented in a webapp error page.

BalusC
Thanks for the reply. I tried your suggestion; however I'm not able to find any errors or any specific servlet libraries for Tomcat 6. All the libraries I see in my WEB-INF/lib are 100% libraries I added manually so I know what they really are.
chris
Here's an interesting solution I did. I made a new Dynamic Web Project for Tomcat 5.5 (2.4). Copied the controller, entity, and view that pertains to the page I'm troubleshooting. Voila! The contents show. The syntax on my controller and jsp is indeed correct (both in Tomcat 5.5 and Tomcat 6). So I'm guessing something is fishy with my original project. I'm gonna try to create a new Web Project and copy-paste my source and libs over there.
chris
ARGGGGGGGGGGHHHHHH!!!!!!!!!! The database is empty that's why!
chris
Okay, I've investigated further. The question is why is the database empty? My project is set-up to auto-import a sql statement. It worked flawlessly with Tomcat 6. All unit-test passed. But on Tomcat 5.5, it failed to import the sql. It turns out that my original TOmcat 5.5 project import file is not on the classpath but it's buried one folder down. So I made a second Tomcat 5.5 project. This time the import.sql is on the classpath.
chris
But still the database is empty. It turns out when I run Tomcat 5.5 from Eclipse, it loaded the old project and the new project. The new projects is loading the import.sql from the old project (which of course fails because it's on the wrong path). To solve the database issue, I either corrected the location of the import.sql on the old project. Or I just closed the old project. I tried both and it worked. My EL expressions are now working. In exchange I had to be absent from work because I spent too many hours last night figuring this out. I gotta rest :)
chris
Another thing. I had to clear cache my browser to see the results because when I did the above steps, I saw my data on my database but empty on my JSP.
chris
Glad you fixed it.
BalusC