0
我想使用Spring MVC製作我的第一個Web項目。
我有問題,當我嘗試顯示已放入我的模型中的變量。
但在我的頁面上看到我的測試參數,但我的表是空的。
請告訴我,我錯過了什麼。參數添加到模型,但沒有在頁面上顯示
進出口使用的瓷磚控制器,所以這是我針對home.jsp的瓷磚,我想表明我的列表:
<div id="indexLeftColumn">
<div id="welcomeText">
<p>[ cool picture ]</p>
</div>
</div>
<div id="indexRightColumn">
<div id="deviceList">
Table with list of devices</br>
${blah}
<table class="table" border="1">
<thead>
<tr>
<th>Device ID</th>
</tr>
</thead>
<tbody>
<c:forEach items="${hubsIDList}" var="hub" >
<tr>
<td>${hub}</td>
</tr>
</c:forEach>
</tbody>
</table>
</div>
</div>
這裏是我的控制器,增加值,並返回我回到Home.jsp 我的一部分增加了新的參數「嗒嗒」只是爲了測試,該參數的其他地方沒有消失
@RequestMapping(value = "/home", method = RequestMethod.GET)
public String home(Model model) {
log.info("Loading homepage");
UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
ArrayList<String> hubsID =(ArrayList<String>) userDetails.getParameter("hubsID"); //checked - it's not empty and truly Array list of Strings
model.addAttribute("hubsIDList",hubsID);
model.addAttribute("blah","Test if parameters still here"); //added for test that my parameters aren't dissapear
return "home";
}
,這裏是我的包括
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<%@ taglib uri="http://tiles.apache.org/tags-tiles" prefix="tiles"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/core" prefix="c"%>
<%@ taglib uri="http://java.sun.com/jsp/jstl/fmt" prefix="fmt" %>
<%@ taglib uri="http://www.springframework.org/tags" prefix="spring" %>
<%@ taglib uri="http://www.springframework.org/tags/form" prefix="spring_form" %>
<%@ taglib uri="http://www.springframework.org/security/tags" prefix="sec" %>
UPD
試過如下使用控制器梅託德,但還是沒有結果 - 測試參數頁面上可見,但表是空
@RequestMapping(value = "/home", method = RequestMethod.GET)
public ModelAndView home(Model model) {
HashMap<String,Object> modelParams = (HashMap)model.asMap();
log.info("Loading homepage");
UserDetailsImpl userDetails = (UserDetailsImpl) SecurityContextHolder.getContext().getAuthentication().getPrincipal();
ArrayList<String> hubsID =(ArrayList<String>) userDetails.getParameter("hubsID");
modelParams.put("hubsIDList",hubsID);
modelParams.put("blah","Test if parameters still here");
return new ModelAndView("home",modelParams);
}
這是什麼意思,「這些參數不會消失在別處」,你說這個參數沒有顯示在頁面中? – Koitoer 2014-11-24 16:55:24
是的,它不顯示 – Asprelis 2014-11-24 17:01:49