JSP下拉框选中一个获取的值,点查询为何只能查询第一页,点下一页又跳回到默认值了?

wjssoft_225 2015-11-26 10:31:40
所属部门:<select name="departmentObj.departmentNo">
<option value="">不限制</option>
<%
for(Department departmentTemp:departmentList) {
%>
<option value="<%=departmentTemp.getDepartmentNo() %>"><%=departmentTemp.getDepartmentName() %></option>
<%
}
%>
</select>
设备名称:<input type=text name="deviceName" value="<%=deviceName %>" /> 
设备数量:<input type=text size="8" name="deviceNum" value="<%=deviceNum %>" /> 
设备状态:<select name="deviceStateObj.deviceStateId">
<option value="0">不限制</option>
<%
for(DeviceState deviceStateTemp:deviceStateList) {
%>
<option value="<%=deviceStateTemp.getDeviceStateId() %>"><%=deviceStateTemp.getDeviceState() %></option>
<%
}
%>
</select>
添加方式:<select name="addWayObj.addWayId">
<option value="0">不限制</option>
<%
for(AddWay addWayTemp:addWayList) {
%>
<option value="<%=addWayTemp.getAddWayId() %>"><%=addWayTemp.getAddWayName() %></option>
<%
}
%>
</select>
出厂日期:<input type=text readonly name="leaveFactoryDate" value="<%=leaveFactoryDate %>" onclick="setDay(this);"/> 
<input type=hidden name=currentPage value="1" />
<input type=submit value="查询" />
</td>
Text文本框就可以,上述的添加方式,状态下拉框不行,第一页点查询后,点下一页有变成不限制了。第二页的数据没变,请各位解答啊。急急急
...全文
248 18 打赏 收藏 转发到动态 举报
AI 作业
写回复
用AI写文章
18 条回复
切换为时间正序
请发表友善的回复…
发表回复
xuteng1 2015-11-26
  • 打赏
  • 举报
回复
<option value="<%=departmentTemp.getDepartmentNo() %>" <%if(department==departmentTemp) {%> <%="selected='selected'" %><%} %>><%=departmentTemp.getDepartmentName() %></option> 把这段代码替换就好使了
wjssoft_225 2015-11-26
  • 打赏
  • 举报
回复
//获取所有的deviceClassObj信息 List<DeviceClass> deviceClassList = (List<DeviceClass>)request.getAttribute("deviceClassList"); DeviceClass deviceClass = (DeviceClass)request.getAttribute("deviceClass"); //获取所有的departmentObj信息 List<Department> departmentList = (List<Department>)request.getAttribute("departmentList"); Department department = (Department)request.getAttribute("department"); 上面已经获取了
wjssoft_225 2015-11-26
  • 打赏
  • 举报
回复
哪里不对,给指明下,修改哪里,我已经修改了好多次了
xuteng1 2015-11-26
  • 打赏
  • 举报
回复
上面的代码稍微改改就好了有的地方写的不对大致就是这个意思
xuteng1 2015-11-26
  • 打赏
  • 举报
回复
所属部门:<select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>" <%if(departmentTemp.getDepartmentNo() .equls((String)request.getAttribute("DepartmentNo"))){%><%=“selected='true'”%>><%=departmentTemp.getDepartmentName() %></option> <% } %> </select> 点击查询请求后台代码 request.setAttribute("DepartmentNo","select选中后带到后台来的值"); 点击下一页的时候你必须带身上select选择的值在后台 request.setAttribute("DepartmentNo","select选中后带到后台来的值");
xuteng1 2015-11-26
  • 打赏
  • 举报
回复
引用 17 楼 wjssoft_225 的回复:
前台点查询的时候的input <input type=hidden name=currentPage value="1" /> <input type=submit value="查询" onclick="QueryDeviceInfo();"/>
首先对于你后台代码
引用 16 楼 wjssoft_225 的回复:
后台查询代码 /*查询DeviceInfo信息*/ public String QueryDeviceInfo() { if(currentPage == 0) currentPage = 1; if(deviceNumber == null) deviceNumber = ""; if(deviceName == null) deviceName = ""; if(leaveFactoryDate == null) leaveFactoryDate = ""; List<DeviceInfo> deviceInfoList = deviceInfoDAO.QueryDeviceInfoInfo(deviceNumber, deviceClassObj, departmentObj, deviceName,deviceNum, deviceStateObj, addWayObj, leaveFactoryDate, currentPage); /*计算总的页数和总的记录数*/ deviceInfoDAO.CalculateTotalPageAndRecordNumber(deviceNumber, deviceClassObj, departmentObj, deviceName, deviceNum,deviceStateObj, addWayObj, leaveFactoryDate); /*获取到总的页码数目*/ totalPage = deviceInfoDAO.getTotalPage(); /*当前查询条件下总记录数*/ recordNumber = deviceInfoDAO.getRecordNumber(); ActionContext ctx = ActionContext.getContext(); ctx.put("deviceInfoList", deviceInfoList); ctx.put("totalPage", totalPage); ctx.put("recordNumber", recordNumber); ctx.put("currentPage", currentPage); ctx.put("deviceNumber", deviceNumber); ctx.put("deviceClassObj", deviceClassObj); DeviceClassDAO deviceClassDAO = new DeviceClassDAO(); List<DeviceClass> deviceClassList = deviceClassDAO.QueryAllDeviceClassInfo(); ctx.put("deviceClassList", deviceClassList); ctx.put("departmentObj", departmentObj); DepartmentDAO departmentDAO = new DepartmentDAO(); List<Department> departmentList = departmentDAO.QueryAllDepartmentInfo(); ctx.put("departmentList", departmentList); ctx.put("deviceName", deviceName); ctx.put("deviceNum", deviceNum); ctx.put("deviceStateObj", deviceStateObj); DeviceStateDAO deviceStateDAO = new DeviceStateDAO(); List<DeviceState> deviceStateList = deviceStateDAO.QueryAllDeviceStateInfo(); ctx.put("deviceStateList", deviceStateList); ctx.put("addWayObj", addWayObj); AddWayDAO addWayDAO = new AddWayDAO(); List<AddWay> addWayList = addWayDAO.QueryAllAddWayInfo(); ctx.put("addWayList", addWayList); ctx.put("leaveFactoryDate", leaveFactoryDate); return "query_view"; }
引用 16 楼 wjssoft_225 的回复:
后台查询代码 /*查询DeviceInfo信息*/ public String QueryDeviceInfo() { if(currentPage == 0) currentPage = 1; if(deviceNumber == null) deviceNumber = ""; if(deviceName == null) deviceName = ""; if(leaveFactoryDate == null) leaveFactoryDate = ""; List<DeviceInfo> deviceInfoList = deviceInfoDAO.QueryDeviceInfoInfo(deviceNumber, deviceClassObj, departmentObj, deviceName,deviceNum, deviceStateObj, addWayObj, leaveFactoryDate, currentPage); /*计算总的页数和总的记录数*/ deviceInfoDAO.CalculateTotalPageAndRecordNumber(deviceNumber, deviceClassObj, departmentObj, deviceName, deviceNum,deviceStateObj, addWayObj, leaveFactoryDate); /*获取到总的页码数目*/ totalPage = deviceInfoDAO.getTotalPage(); /*当前查询条件下总记录数*/ recordNumber = deviceInfoDAO.getRecordNumber(); ActionContext ctx = ActionContext.getContext(); ctx.put("deviceInfoList", deviceInfoList); ctx.put("totalPage", totalPage); ctx.put("recordNumber", recordNumber); ctx.put("currentPage", currentPage); ctx.put("deviceNumber", deviceNumber); ctx.put("deviceClassObj", deviceClassObj); DeviceClassDAO deviceClassDAO = new DeviceClassDAO(); List<DeviceClass> deviceClassList = deviceClassDAO.QueryAllDeviceClassInfo(); ctx.put("deviceClassList", deviceClassList); ctx.put("departmentObj", departmentObj); DepartmentDAO departmentDAO = new DepartmentDAO(); List<Department> departmentList = departmentDAO.QueryAllDepartmentInfo(); ctx.put("departmentList", departmentList); ctx.put("deviceName", deviceName); ctx.put("deviceNum", deviceNum); ctx.put("deviceStateObj", deviceStateObj); DeviceStateDAO deviceStateDAO = new DeviceStateDAO(); List<DeviceState> deviceStateList = deviceStateDAO.QueryAllDeviceStateInfo(); ctx.put("deviceStateList", deviceStateList); ctx.put("addWayObj", addWayObj); AddWayDAO addWayDAO = new AddWayDAO(); List<AddWay> addWayList = addWayDAO.QueryAllAddWayInfo(); ctx.put("addWayList", addWayList); ctx.put("leaveFactoryDate", leaveFactoryDate); return "query_view"; }
Department department = (Department)request.getAttribute("department");你的页面有这段代码 改成 Department department = (Department)request.getAttribute("departmentObj"); 然后option里面改成10楼那样,再试试
wjssoft_225 2015-11-26
  • 打赏
  • 举报
回复
换了还不行, 所属部门:<select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>" <%if(department==departmentTemp) {%> <%="selected='selected'" %><%} %>><%=departmentTemp.getDepartmentName() %></option> <% } %>
wjssoft_225 2015-11-26
  • 打赏
  • 举报
回复
前台点查询的时候的input <input type=hidden name=currentPage value="1" /> <input type=submit value="查询" onclick="QueryDeviceInfo();"/>
wjssoft_225 2015-11-26
  • 打赏
  • 举报
回复
后台查询代码 /*查询DeviceInfo信息*/ public String QueryDeviceInfo() { if(currentPage == 0) currentPage = 1; if(deviceNumber == null) deviceNumber = ""; if(deviceName == null) deviceName = ""; if(leaveFactoryDate == null) leaveFactoryDate = ""; List<DeviceInfo> deviceInfoList = deviceInfoDAO.QueryDeviceInfoInfo(deviceNumber, deviceClassObj, departmentObj, deviceName,deviceNum, deviceStateObj, addWayObj, leaveFactoryDate, currentPage); /*计算总的页数和总的记录数*/ deviceInfoDAO.CalculateTotalPageAndRecordNumber(deviceNumber, deviceClassObj, departmentObj, deviceName, deviceNum,deviceStateObj, addWayObj, leaveFactoryDate); /*获取到总的页码数目*/ totalPage = deviceInfoDAO.getTotalPage(); /*当前查询条件下总记录数*/ recordNumber = deviceInfoDAO.getRecordNumber(); ActionContext ctx = ActionContext.getContext(); ctx.put("deviceInfoList", deviceInfoList); ctx.put("totalPage", totalPage); ctx.put("recordNumber", recordNumber); ctx.put("currentPage", currentPage); ctx.put("deviceNumber", deviceNumber); ctx.put("deviceClassObj", deviceClassObj); DeviceClassDAO deviceClassDAO = new DeviceClassDAO(); List<DeviceClass> deviceClassList = deviceClassDAO.QueryAllDeviceClassInfo(); ctx.put("deviceClassList", deviceClassList); ctx.put("departmentObj", departmentObj); DepartmentDAO departmentDAO = new DepartmentDAO(); List<Department> departmentList = departmentDAO.QueryAllDepartmentInfo(); ctx.put("departmentList", departmentList); ctx.put("deviceName", deviceName); ctx.put("deviceNum", deviceNum); ctx.put("deviceStateObj", deviceStateObj); DeviceStateDAO deviceStateDAO = new DeviceStateDAO(); List<DeviceState> deviceStateList = deviceStateDAO.QueryAllDeviceStateInfo(); ctx.put("deviceStateList", deviceStateList); ctx.put("addWayObj", addWayObj); AddWayDAO addWayDAO = new AddWayDAO(); List<AddWay> addWayList = addWayDAO.QueryAllAddWayInfo(); ctx.put("addWayList", addWayList); ctx.put("leaveFactoryDate", leaveFactoryDate); return "query_view"; }
xuteng1 2015-11-26
  • 打赏
  • 举报
回复
引用 13 楼 xuteng1 的回复:
[quote=引用 12 楼 wjssoft_225 的回复:] 所属部门:<select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>"<%if(departmentTemp.getDepartmentNo() ==request.getAttribute("DepartmentNo")){%> <%="selected='selected'" %><%}%>><%=departmentTemp.getDepartmentName() %></option> <% } %> </select 为什么还是会变回默认值,第二页查询不了条件的值,变回不限制了
把你的页面后后台代码全贴出来我看下[/quote] 你换错代码了你看看十楼我给你回复的
xuteng1 2015-11-26
  • 打赏
  • 举报
回复
引用 12 楼 wjssoft_225 的回复:
所属部门:<select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>"<%if(departmentTemp.getDepartmentNo() ==request.getAttribute("DepartmentNo")){%> <%="selected='selected'" %><%}%>><%=departmentTemp.getDepartmentName() %></option> <% } %> </select 为什么还是会变回默认值,第二页查询不了条件的值,变回不限制了
把你的页面后后台代码全贴出来我看下
wjssoft_225 2015-11-26
  • 打赏
  • 举报
回复
所属部门:<select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>"<%if(departmentTemp.getDepartmentNo() ==request.getAttribute("DepartmentNo")){%> <%="selected='selected'" %><%}%>><%=departmentTemp.getDepartmentName() %></option> <% } %> </select 为什么还是会变回默认值,第二页查询不了条件的值,变回不限制了
xuteng1 2015-11-26
  • 打赏
  • 举报
回复
引用 10 楼 xuteng1 的回复:
[quote=引用 7 楼 wjssoft_225 的回复:] 所属部门:<select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>"><%=departmentTemp.getDepartmentName() %></option> <% } %> </select> 请问,你这是代码是替换全部的这个部分吗?
这段代码 <option value="<%=departmentTemp.getDepartmentNo() %>" <%if(department==departmentTemp) {%> <%="selected='selected'" %><%} %>><%=departmentTemp.getDepartmentName() %></option> 替换 <select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>"><%=departmentTemp.getDepartmentName() %></option> <% } %> </select> 标红的地方[/quote] 如果还不行你只有把点击查询后的后台代码贴出来了
xuteng1 2015-11-26
  • 打赏
  • 举报
回复
引用 7 楼 wjssoft_225 的回复:
所属部门:<select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>"><%=departmentTemp.getDepartmentName() %></option> <% } %> </select> 请问,你这是代码是替换全部的这个部分吗?
这段代码 <option value="<%=departmentTemp.getDepartmentNo() %>" <%if(department==departmentTemp) {%> <%="selected='selected'" %><%} %>><%=departmentTemp.getDepartmentName() %></option> 替换 <select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>"><%=departmentTemp.getDepartmentName() %></option> <% } %> </select> 标红的地方
wjssoft_225 2015-11-26
  • 打赏
  • 举报
回复
换成那个代码还是不行
wjssoft_225 2015-11-26
  • 打赏
  • 举报
回复
加完这个,上一页,下一页点不动了,而且下拉框点查询完还是变成不限制了
wjssoft_225 2015-11-26
  • 打赏
  • 举报
回复
所属部门:<select name="departmentObj.departmentNo"> <option value="">不限制</option> <% for(Department departmentTemp:departmentList) { %> <option value="<%=departmentTemp.getDepartmentNo() %>"><%=departmentTemp.getDepartmentName() %></option> <% } %> </select> 请问,你这是代码是替换全部的这个部分吗?
Cx_轩 2015-11-26
  • 打赏
  • 举报
回复
加个selected = selected

81,122

社区成员

发帖
与我相关
我的任务
社区描述
Java Web 开发
社区管理员
  • Web 开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧