如何在SpringMVC和ApacheTiles中更新JSP
我在我的Spring3MVC应用程序中使用ApacheTiles 2,布局是:左边是菜单,右边是正文 layout.jsp如何在SpringMVC和ApacheTiles中更新JSP,spring,spring-mvc,tiles2,Spring,Spring Mvc,Tiles2,我在我的Spring3MVC应用程序中使用ApacheTiles 2,布局是:左边是菜单,右边是正文 layout.jsp <table> <tr> <td height="250"><tiles:insertAttribute name="menu" /></td> <td width="350"><tiles:insertAttribute name="body" /></td>
<table>
<tr>
<td height="250"><tiles:insertAttribute name="menu" /></td>
<td width="350"><tiles:insertAttribute name="body" /></td>
</tr>
</table>
menu.jsp
<div><ul>
<li><a href="account.html">account</a></li>
<li><a href="history.html">history</a></li></ul></div>
body of history.jsp
<c:forEach var="history" items="${histories}"><p><c:out value="${history}"></c:out></p></c:forEach>
我还有一个历史控制器
@Controller
public class HistoryController {
@RequestMapping("/history")
public ModelAndView showHistory() {
ArrayList <String> histories = read from DB.
return new ModelAndView("history","histories",histories);
}
}
因此,每次单击菜单上的历史链接时,都会调用showHistory
但还有一个更复杂的情况。history DB有数百个条目,因此我们决定只在history.jsp第一次显示时显示前10个条目,然后向history.jsp添加一个show more histories按钮,通过添加另一个控制器来显示下10个条目
问题是,当用户执行以下操作时:
点击历史链接,显示0-9条历史,
单击“显示更多历史记录”以显示10到19,
单击帐户链接返回帐户页面,
再次单击history链接,它显示0-9,而不是history.jsp显示10到19。
如何使history.jsp显示上次访问的历史,而不是从头开始显示
我对春天很陌生,欢迎大家提出建议。
谢谢。您要做的是将上次请求的范围存储在会话中。如果用户未在请求中指定范围,则使用存储在上的会话 像这样的
@RequestMapping("/history")
public ModelAndView showHistory(@RequestParam(value="startIndex", defaultValue="-1") Integer startIndex, HttpSession session) {
Integer start = Integer.valueOf(0);
if (startIndex == null || startIndex.intValue() < 0) {
// get from session
Integer sessionStartIndex = (Integer) session.getAttribute("startIndex");
if (sessionStartIndex != null) {
start = sessionStartIndex;
}
} else {
start = startIndex;
}
session.setAttribute("startIndex", start);
ArrayList <String> histories = read from DB, starting with start.
return new ModelAndView("history","histories",histories);
}
谢谢,会议将是一个选择。请明确,在这种情况下,我只是在会话中存储一个指针,如果需要存储更多的数据,例如网页的HTML代码,那么更好的方法是什么?通常在会话中存储任何数据都没有问题。只要你意识到这些限制。例如,如果在会话中存储大型或不可序列化的数据,则应关闭会话序列化。此外,请记住内存消耗。