我有一个 SpringController 获取一个名为“start”的 RequestParameter 用于搜索/休眠分页目的。如果参数为空,只需从零开始并使用 JavaScript var 'start = {start + 10}' 渲染一个 JSP,因此如果用户单击“下一个 10”按钮,控制器会得到一个 'start = 10' . 然后,控制器应该渲染一个带有'start = {start + 10} = 20的JSP,但无论我通过控制器多少次,它仍然是10。我在服务器端和客户端都做了添加。同样的事情发生:什么都没有。这是控制器方法:
@RequestMapping(value = "/customers", method = RequestMethod.GET)
public String customersView(@RequestParam(value = "start", required = false) Integer start, ModelMap model) {
if (start == null || start <= 0) start = 0;
List<Customer> customers = customerService.findAllCustomers(start, pagesize);
CustomersForm customersForm = new CustomersForm();
customersForm.setCustomers(customers);
start += 10; // I can see a "20" here, actually.
model.clear();
model.addAttribute("customersform", customersForm);
model.addAttribute("start", start); //This should render a "20" on client side on the first call, but it doesn't.
return "customers";
}
这是 JSP 的相关部分:
<script type="text/javascript">
jq(document).ready(function() {
jq("#next_20").click(function() {
var st = "${start}"; //This gets set OK only first time, i.e., a "10" is rendered.
jq.get("customers",
{
start: st
});
});
});
好的,现在我也将这些行添加到我的 servlet-context 中,因为我怀疑它与某些缓存部分(浏览器、Tomcat)正在做的事情有关......:
<!-- Disable web cache for GET requests -->
<mvc:interceptors>
<bean id="webContentInterceptor"
class="org.springframework.web.servlet.mvc.WebContentInterceptor">
<property name="cacheSeconds" value="0" />
<property name="useExpiresHeader" value="true" />
<property name="useCacheControlHeader" value="true" />
<property name="useCacheControlNoStore" value="true" />
</bean>
</mvc:interceptors>
就是这样。当我点击“next_20”按钮时,我的控制器被调用,一个“start”参数被传递(10)并且应该在模型中被替换为“20”,但渲染的页面仍然有一个“10”。
我究竟做错了什么?
干杯