1、把下拉框的值传到后台,存入session中
//前台
function changePageSize() {
//获取下拉框的值
var pageSize = $("#changePageSize").val();
//向服务器发送请求,改变没页显示条数
location.href = "${pageContext.request.contextPath}/product/findByNameAndDesc.do?selectValue="+pageSize+"&productName=${search_productName}&productDesc=${search_productDesc}&page=1&pageSize="+ pageSize;
}
//后台
//多个模糊查询
@RequestMapping("/findByNameAndDesc.do")
public ModelAndView findByNameAndDesc(@RequestParam(name="productName",required = true) String productName,
@RequestParam(name = "productDesc",required = true) String productDesc,
@RequestParam(name = "page",required = true,defaultValue = "1")int page,
@RequestParam(name = "pageSize",required = true,defaultValue = "4")int size,
@RequestParam(name = "selectValue",required = false)String selectValue,
HttpSession session) throws Exception {
ModelAndView mv = new ModelAndView();
List<Product> products = productService.findByNameAndDesc(productName,productDesc,page,size);
PageInfo pageInfo = new PageInfo(products);
mv.addObject("pageInfo", pageInfo);
mv.addObject("search_productName",productName);
mv.addObject("search_productDesc",productDesc);
if (selectValue != null){
session.setAttribute("selectValue",selectValue);
}
mv.setViewName("product-list1");
return mv;
}
2、在JSP页面中使用< c:if>< /c:if >判断
<select class="form-control" id="changePageSize" onchange="changePageSize()">
<c:if test="${selectValue=='1'}">
<option selected>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</c:if>
<c:if test="${selectValue=='2'}">
<option>1</option>
<option selected>2</option>
<option>3</option>
<option>4</option>
<option>5</option>
</c:if>
<c:if test="${selectValue=='3'}">
<option>1</option>
<option>2</option>
<option selected>3</option>
<option>4</option>
<option>5</option>
</c:if>
<c:if test="${selectValue=='4'}">
<option>1</option>
<option>2</option>
<option>3</option>
<option selected>4</option>
<option>5</option>
</c:if>
<c:if test="${selectValue=='5'}">
<option>1</option>
<option>2</option>
<option>3</option>
<option>4</option>
<option selected>5</option>
</c:if>
注意if标签的写法:<c:if test="${selectValue=='5'}">