1. 对于一般的文本框直接将输入的添加到request域中回显。
// 组装名称 String queryName = request.getParameter("queryName"); // 如果是点击页号提交方式为get提交进行转码 if (getTag != null && !"".equals(getTag.trim())) { queryName = new String(queryName.getBytes("iso-8859-1"), "utf-8"); } if (queryName != null && !"".equals(queryName)) { condition.setQueryName(queryName); // 回显数据 request.setAttribute("queryName", queryName); }
JSP页面中用EL表达式取出数据:
<div class="input-group fudong"> <span class="input-group-addon">名称</span> <input type="text" class="form-control" placeholder="请输入名称进行查询" name="queryName" value="${queryName}"> </div>
2.对于下拉列表选择的数据回显
// 组装日期 String queryDate = request.getParameter("queryDate"); /* if (getTag != null && !"".equals(getTag.trim())) { queryDate = new String(queryAddress.getBytes("iso-8859-1"), "utf-8"); }*/ if (queryDate != null && !"".equals(queryDate)) { if ("1".equals(queryDate)) { System.out.println(queryDate); Date date = new Date(); date.setMonth(date.getMonth() - 3); condition.setQueryDate(date); } if ("2".equals(queryDate)) { System.out.println(queryDate); Date date = new Date(); System.out.println(date); date.setMonth(date.getMonth() - 6); System.out.println(date); condition.setQueryDate(date); } if ("3".equals(queryDate)) { System.out.println(queryDate); Date date = new Date(); System.out.println(date); date.setMonth(date.getMonth() - 12); System.out.println(date); condition.setQueryDate(date); } request.setAttribute("queryDate", queryDate); }
JSP页面根据回显的值判断选中的选项:
<div class="input-group fudong"> <span class="input-group-addon ">购建日期</span> <select class="form-control" name="queryDate"> <option>请选择期限</option> <option value="1" <c:if test="${'1' eq queryDate}">selected</c:if>>最近三个月</option> <option value="2" <c:if test="${'2' eq queryDate}">selected</c:if>>最近6个月</option> <option value="3" <c:if test="${'3' eq queryDate}">selected</c:if>>最近一年</option> </select> </div>