简体   繁体   中英

Spring MVC having trouble getting JSP to display Controller Value

I am new to Spring MVC I have setup a test DB to try to get a single flow through and have a table displayed in a JSP page. I assume I have something configured wrong but I cannot find it. Maybe a naming convention.

I have a mySql DB A DAO Class that just does a select * from my table that works as I can step into it.

My controller just gets a list of my Run Models. No errors are thrown The JSP simple loads an empty table. The controller seems to have the correct info in it.

Model (snippet all the getters and setters seem to work as the controller gets a list of them fine)

public class QAModel {

private int idRun;
private String SuiteID;
private String run_name;

Controller Code

    @RequestMapping(value="/RunList")
public ModelAndView listRun(ModelAndView model) throws IOException{
    //@ModelAttribute
    System.out.println("**** Controller ******");

    List<QAModel> listRun = runDao.list();
    model.addObject("RunList", listRun);
    model.setViewName("RunList");

    return model;
}

That does get a list of Run Model Objects that contain the correct DB info I can see them if I step into it. However the JSP loads a blank table.

JSP Code (I assume I'm missing some mapping or naming convention?)

    <%@ page language="java" contentType="text/html; charset=UTF-8"
    pageEncoding="UTF-8"%>
<!DOCTYPE html PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN" "http://www.w3.org/TR/html4/loose.dtd">
<html>
    <head>
        <meta http-equiv="Content-Type" content="text/html; charset=UTF-8">
        <title>Contact Manager Home</title>
    </head>
    <body>
        <div align="center">
            <h1>Contact List</h1>
            <h3><a href="/newRun">New Run</a></h3>
            <table border="1">
                <th>No</th>
                <th>Suite ID</th>
                <th>Run Name</th>


                <c:forEach var="QAModel" items="${RunList}" varStatus="status">
                    <tr>
                        <td>${status.index + 1}</td>
                        <td>${QAModel.SuiteID}</td>
                        <td>${QAModel.run_name}</td>

                    <td>
                        <a href="/editRun?id=${run.id}">Edit</a>
                        &nbsp;&nbsp;&nbsp;&nbsp;
                        <a href="/deleteRun?id=${run.id}">Delete</a>
                    </td>

                    </tr>
                </c:forEach>

            </table>
        </div>
    </body>
</html>

If you are not able to print any jstl variable then one possible reason can be that your jstl core tag is not added.

Add this to begining of your JSP file.

<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c" %>

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM