0

I'm trying to build simple MVC spring web app from this source :

https://javapipe.com/spring-mvc-web-application-tutorial-with-examples-part-1

I tried to retrieve the list of Purchase Requests & set it to model attribute however on the view it's only showing the jstl tag without its value E.g ${request.poNumber}

Here's my Controller snippet :

@Controller 
@RequestMapping("/purchase-request") 
public class PurchaseRequestController {
    private static final String MY_REQUESTS_VIEW = "myRequests";
    private static final String MY_REQUESTS_MODEL_ATTRIBUTE = "myRequestList";

    @Resource
    private PurchaseRequestService purchaseRequestService;

    @RequestMapping(value = "/myRequests", method = RequestMethod.GET) 
    public String getMyRequests(Model model){ 
        System.out.println("Data g: "+purchaseRequestService.getAllPurchaseRequests().get(0).getPoNumber());
        model.addAttribute(MY_REQUESTS_MODEL_ATTRIBUTE, purchaseRequestService.getAllPurchaseRequests()); 
        return MY_REQUESTS_VIEW; 
    }
}

it's my view (myRequests.jsp) :

<%@ page language="java" contentType="text/html; charset=US-ASCII"
    pageEncoding="US-ASCII"%>
<!DOCTYPE html>
<html lang="en">
<head>
<title>Purchase Requests</title>
<meta name="viewport" content="width=device-width, initial-scale=1">
<link rel="stylesheet"
    href="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/css/bootstrap.min.css">
<script
    src="https://ajax.googleapis.com/ajax/libs/jquery/1.11.3/jquery.min.js"></script>
<script
    src="http://maxcdn.bootstrapcdn.com/bootstrap/3.3.5/js/bootstrap.min.js"></script>
<%@ taglib prefix="c" uri="http://java.sun.com/jsp/jstl/core"%>
<jsp:useBean id="myRequestList" scope="request" type="java.util.List" />
</head>
<body>
    <c:if test="${not empty myRequestList}">
        Hello
        <ul>
            <c:forEach var="listValue" items="${myRequestList}">
                <li>${listValue}</li>
            </c:forEach>
        </ul>

    </c:if>

    <div class="container-fluid">
        <div class="page-header">
            <h1>Purchase Requests</h1>
        </div>
        <div class="row">
            <ul class="nav nav-tabs">
                <li role="presentation" class="active"><a href="#">Saved</a></li>
                <li role="presentation"><a href="#">Submitted</a></li>
                <li role="presentation"><a href="#">Approved</a></li>
            </ul>
        </div>
        <div class="row">
            <table class="table">
                <thead>
                    <tr>
                        <th>PO Number</th>
                        <th>Date</th>
                        <th>Justification</th>
                    </tr>
                </thead>
                <tbody>
                    <c:forEach items="${myRequestList}" var="request">
                        <tr>
                            <td>${request.poNumber}</td>
                            <td>${request.date}</td>
                            <td>${request.justification}</td>
                        </tr>
                    </c:forEach>
                </tbody>
            </table>
        </div>
    </div>
</body>
</html>

my POM.xml :

<dependencies>
        <dependency>
            <groupId>junit</groupId>
            <artifactId>junit</artifactId>
            <version>3.8.1</version>
            <scope>test</scope>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-context</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>org.springframework</groupId>
            <artifactId>spring-webmvc</artifactId>
            <version>4.1.1.RELEASE</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>jstl</artifactId>
            <version>1.2</version>
        </dependency>
        <dependency>
            <groupId>javax.servlet</groupId>
            <artifactId>javax.servlet-api</artifactId>
            <version>3.0.1</version>
            <scope>provided</scope>
        </dependency>
    </dependencies>

I tried to print out value of the list in the Controller, it's shown correctly in the Eclipse console, but not in the view.

Is there something I missed here?

Thanks in advance

Yagi
  • 511
  • 2
  • 5
  • 19
  • you don't need this line ``, try removing it – Amit.rk3 Aug 16 '15 at 17:15
  • *"however on the view it's only showing the jstl tag without its value"* This is not a terribly clear description of the problem symptoms. You mean to say, when you do rightclick and *View Source* in webbrowser, then you're still seeing all JSTL `` tags in there? In other words, they are not recognized, parsed and executed by the server and therefore they ended up plain vanilla in generated HTML output? But all those EL expressions in their attributes `${...}` are properly recognized and parsed? – BalusC Aug 17 '15 at 07:34
  • Amit.rk3 : thanks, but it's still not working. @BalusC Sorry if my explanation is not clear. I mean, when I tried to run it on web browser, it's just showing : ${request.poNumber} instead of its value. Did I miss something ? – Yagi Aug 18 '15 at 10:32
  • Wow.. you're right @BalusC ! I tried to remove the doctype thing and it works now. I will bookmark your reference link for my learning purpose. Thanks a lot! :D – Yagi Aug 18 '15 at 12:48

0 Answers0