勾选后点击下一页,再点击上一页会发现勾选的东西没有了!该如何解决啊?
如果用session的话应该怎么写?新手还请各位指教!
代码如下:<form action="MyJsp.jsp" method="get">
<table width="200" border="1">
<%
Connection con = null;
Statement stat = null;
try { 
Class.forName("org.gjt.mm.mysql.Driver");
String url = "jdbc:mysql://localhost/testfornothing?user=root&password=123456";
con = DriverManager.getConnection(url);
stat = con.createStatement();
String sql = "select * from TESTCHECKBOX";
ResultSet rs2 = stat.executeQuery(sql);
int intPageSize;
int intRowCount;
int intPageCount;
int intPage;
String strPage;
int i;intPageSize = 5;strPage = request.getParameter("page");
if (strPage == null)
intPage = 1;
else {
intPage = java.lang.Integer.parseInt(strPage);
if (intPage < 1)
intPage = 1;
}rs2.last();
intRowCount = rs2.getRow();
intPageCount = (intRowCount + intPageSize - 1) / intPageSize;
if (intPage > intPageCount)
intPage = intPageCount;
if (intPageCount > 0)
rs2.absolute((intPage - 1) * intPageSize + 1);
i = 0;while (i < intPageSize && !rs2.isAfterLast()) {
%>
<tr>
<td><%=rs2.getString("NAME")%></td>
<td>
<input type="checkbox" name="c1" value="<%=rs2.getInt("NameID")%>" onclick="getcheckbox()" /></td>
</tr> 
<%
rs2.next();
i++;
}
%>
</table>
第<%=intPage%>页 共<%=intRowCount%> 条记录/共<%=intPageCount%>页 
<%if(intPage<2){ %> 首页 | 上一页 
<% }else{%> <a href="index.jsp?page=1">首页</a>|<a href="index.jsp?page=<%=intPage-1%>">上一页</a> 
<%}%> 
<%if((intPageCount-intPage)<1){ %>下一页 | 尾页 
<%}else{%> 
<a href="index.jsp?page=<%=intPage+1%>">下一页</a> | <a href="index.jsp?page=<%=intPageCount%>">尾页</a> 
<%}%> 
<%rs2.close(); 
} catch (Exception e) {
e.printStackTrace();
} finally {
stat.close();
con.close();
}
%>
<input type="submit" name="submit" value="submit" >
</form>

解决方案 »

  1.   

    使用表达式语言EL配合JSTL标签很容易就可以实现了。比如下拉栏默认显示的值可以根据oper的值进行动态显示:
    <select name="oper">
    <option  value="+" <c:if test="${oper=='+'}">selected</c:if>>+</option>
    <option  value="-" <c:if test="${oper=='-'}">selected</c:if>>-</option>
    <option  value="*" <c:if test="${oper=='*'}">selected</c:if>>*</option>
    <option  value="/" <c:if test="${oper=='/'}">selected</c:if>>/</option>
    </select>
    相应的CHACKBOX也可以实现。只要注意两次页面变换时,oper的值是否正常传递。