JSP中表单内容实现分页提交

页面要求:在注册页面中需要完成注册的信息比较的多,需要分多页进行内容填写。

通过 javascript 设置整个页面的不同模块的 css (即style属性)属性,来决定在点击不同的button 的时候显示不同的注册子页面 , 这样,页面 请求并没有发生改变 , 只是当前网页显示的内容发生了改变 ,所以,请求中已填写的参数不会丢失 。

页面代码:每个子页面以 div 来分割, 所以只要改变相应的div 的visibility 和display 的属性就可以了。(style="visibility:visiable;display:inline" 表示显示页面,style="visibility:hidden;display:none" 表示隐藏页面 );显示代码

<%@ page contentType="text/html; charset=gb2312" language="java"
import="java.sql.*" errorPage=""%>
<!DOCTYPE html PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN" "http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">


<html xmlns="http://www.w3.org/1999/xhtml">
<head>
<meta http-equiv="Content-Type" content="text/html; charset=gb2312" />
<title>分页测试</title>
<script type="text/javascript" src="js/jquery-2.1.4.js"></script>
<script type="text/javascript">
function showPage(page) {
//var div = document.getElementById(page);
var div=document.getElementById(page);
if (div != null) {
div.style.visibility = "visible";
div.style.display = "inline";
}
}


function hidePage(page) {
//var div = document.getElementByIdx_x_x(page);
var div=document.getElementById(page);
if (div != null) {

div.style.visibility = 'hidden';
div.style.display = 'none';

}
}

function switchPage(hiddenPage, shownPage) {
hidePage(hiddenPage);
showPage(shownPage);
}
</script>
<style>
.td {
width: 110px;
height: 30px;
}
</style>
</head>
<body>
<form action="<%=request.getContextPath()%>/stud_index_evaluationServ"
method="post" name="frm1" enctype="multipart/form-data">


<div id="page1" style="text-align:center; visibility:visible; display: inline">
<center>
<table>
<tr>
<td class="td">姓名</td>
<td class="td"><input type="text" name="name"
value="<%=strName%>" />
<td class="td">性别</td>
<td class="td"><select name="gender" id="gender">
<%
String selectGender = "selected='selected'";
%>
<option value="男"
<%=strGender.equalsIgnoreCase("男") ? selectGender : null%>>男</option>
<option value="党员"
<%=strGender.equalsIgnoreCase("女") ? selectGender : null%>>女</option>
</select></td>
</tr>
<tr>
<td class="td">学号</td>
<td class="td"><input type="text" name="studno"
value=<%=strStudno%> />
<td class="td">身份证号</td>
<td colspan=""><input type="text" name="id" value=<%=strId%> /></td>
</tr>

<tr>
<td class="td">家庭通讯地址</td>
<td colspan="70"><textarea rows="1" cols="57"
name="postaddress" value=<%=strAddress%>></textarea></td>
</tr>
<tr><td class="td" colspan="100" align="center"><input type="button" value="下一步" οnclick="switchPage('page1','page2')"/></td></tr>
</table>
<%
}
%>
</center>
</div>
<div id="page2" style="text-align:center; visibility:hidden; display:none">
<center>
<table>
<tr>
<td class="td">受到惩处情况</td>
<td colspan=""><textarea rows="5" cols="45"
name="achievepunishment" οnfοcus="if(value!=null){value=''}"
οnblur="if(value==''){value='请输入内容'}">统计所有处罚情况、包括收到院级通报批判以上的各类通报即学校处分等</textarea>
<td class="td">上传材料附件</td>
<td class="td"><input type="file" name="filepunishment"
id="filepunishment" value="附件"> </input></td></td>
</tr>
<tr><td class="td" colspan="100" align="center"><input type="button" value="上一步" οnclick="switchPage('page2','page1')"/></td></tr>
<tr>
<td class="td" colspan="100" align="center"><input
type="submit" id="sub_test" value="提交" />&nbsp;&nbsp;&nbsp; <input
type="reset" value="重置" />&nbsp;&nbsp;&nbsp;
<button id="btn" style="display: none">测试JQuery</button></td>
</tr>
</table>
</center>
</div>
</form>
</body>
</html>

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 1
    评论
package com; public class Pager { private int totalRows = 0; // 记录总数 private int totalPages = 0; // 总页数 private int pageSize = 10; // 每页显示数据条数,默认为10条记录 private int currentPage = 1; // 当前页数 private boolean hasPrevious = false; // 是否有上一页 private boolean hasNext = false; // 是否有下一页 public int getSearchFrom() { return (currentPage - 1) * pageSize; } public Pager() { } public void init(int totalRows) { this.totalRows = totalRows; this.totalPages = ((totalRows + pageSize) - 1) / pageSize; refresh(); // 刷新当前页面信息 } /** * * @return Returns the currentPage. * */ public int getCurrentPage() { return currentPage; } /** * * @param currentPage * current page * */ public void setCurrentPage(int currentPage) { this.currentPage = currentPage; refresh(); } /** * * @return Returns the pageSize. * */ public int getPageSize() { return pageSize; } /** * * @param pageSize * The pageSize to set. * */ public void setPageSize(int pageSize) { this.pageSize = pageSize; refresh(); } /** * * @return Returns the totalPages. * */ public int getTotalPages() { return totalPages; } /** * * @param totalPages * The totalPages to set. * */ public void setTotalPages(int totalPages) { this.totalPages = totalPages; refresh(); } /** * * @return Returns the totalRows. * */ public int getTotalRows() { return totalRows; } /** * * @param totalRows * The totalRows to set. * */ public void setTotalRows(int totalRows) { this.totalRows = totalRows; refresh(); } // 跳到第一页 public void first() { currentPage = 1; this.setHasPrevious(false); refresh(); } // 取得上一页(重新设定当前页面即可) public void previous() { if (currentPage > 1) { currentPage--; } refresh(); } // 取得下一页 public void next() { //System.out.println("next: totalPages: "

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值