📄 operatepage.java
字号:
{
throw new OperateException(OperateConst.EXCEPTION_TYPE_CON_IS_NULL);
}
//检查必要设置
if(this.pageUrl == null) /*如传递的跳转页面为空,抛出异常*/
{
throw new OperateException(OperateConst.EXCEPTION_TYPE_URL_IS_NULL);
}
//主体操作
StringBuffer strBuf = new StringBuffer("");
int pageSize=pm_iPageSize,pageIndex=pm_iPageIndex;
// 判断是第一次进入还是翻页操作,设置相应的pageSize和pageIndex
if(request.getParameter("pageSizeText")==null)
{
pageSize = pm_iPageSize;
}
else if(!request.getParameter("pageSizeText").equals(""))
{
pageSize = Integer.parseInt(request.getParameter("pageSizeText"));
}
if(request.getParameter("pageIndex")==null)
{
pageIndex = pm_iPageIndex;
}
else if(request.getParameter("pageIndex")!=null)
{
pageIndex = Integer.parseInt(request.getParameter("pageIndex"));
}
//如跳转类型为Action,在url中加flag=pageOperate参数以便在用户的Action中标识跳转操作(默认为跳转到原jsp)
if(this.forwardType == OperateConst.FOWARD_TYPE_ACTION)
{
this.pageUrl = this.pageUrl+"?flag=pageOperate&";
}
else if(this.forwardType == OperateConst.FOWARD_TYPE_JSP)
{
this.pageUrl = this.pageUrl+"?";
}
int pageBegin = pageSize*pageIndex;
int pageEnd = pageSize*(pageIndex+1)-1;
String pageUrlReal = this.pageUrl;
int pageTotal = 0;
sql = "select * from (select rownum r, t. * from ("+pm_sSql +") t where rownum <="+(pageEnd+1)+") t_out where r >="+(pageBegin+1);
//获取总页数
PageDbBean dbBean = new PageDbBean(this.con);
int rowTotal = dbBean.getTotalCount(pm_sSql);
pageTotal = rowTotal/pm_iPageSize;
if(pageTotal*pm_iPageSize<rowTotal)
{
pageTotal = pageTotal + 1;
}
//如未设置form名,则将分页数据封装在名为"form1"的表单中
if(this.getFormName().equals(""))
{
this.setFormName("form1");
this.setSelfForm(true);
strBuf.append("<form name="+this.formName+" action='' method=post>");
strBuf.append("\n");
}
else if( (!this.getFormName().equals(""))&&this.isSelfForm==true)
{
this.setFormName("form1");
strBuf.append("<form name="+this.formName+" action='' method=post>");
strBuf.append("\n");
}
//主体操作
this.contentTitle = new String[100];
Vector result = dbBean.getResultBySql2(sql,this.contentTitle);
Vector vecContent = result;
strBuf.append("<table width=100% cellspacing=1 cellpadding=0>");
//表格标题栏
strBuf.append("<tr >");
if(this.hasSelectItem)
{
strBuf.append("<td >");
if(this.selectType == OperateConst.SELECT_TYPE_CHECKBOX)
{
strBuf.append("<input type='checkbox' name='checkAll' onclick='doSelectAll();'/>");
}
strBuf.append("</td>");
}
for(int i=0;i<contentTitle.length;i++)
{
strBuf.append("<td>"+contentTitle[i]+"</td>");
}
strBuf.append("</tr>");
for(int i=0;i<vecContent.size();i++)
{
Vector tmp = (Vector)vecContent.get(i);
strBuf.append("<tr>");
if(this.hasSelectItem)
{
strBuf.append("<td>");
if(this.selectType == OperateConst.SELECT_TYPE_CHECKBOX)
{
strBuf.append("<input type='checkbox' name='"+this.getSelectItemName()+"' value='");
for(int k=0;k<this.selectKeyArray.length;k++)
{
strBuf.append(tmp.get(selectKeyArray[k]-1)+";");
}
strBuf.append("'/>");
}
else if(this.selectType == OperateConst.SELECT_TYPE_RADIOBUTTON)
{
strBuf.append("<input type='radio' name='"+this.getSelectItemName()+"' value='");
for(int k=0;k<this.selectKeyArray.length;k++)
{
strBuf.append(tmp.get(selectKeyArray[k]-1)+";");
}
strBuf.append("'/>");
}
strBuf.append("</td>");
}
for(int j=0;j<tmp.size();j++)
{
strBuf.append("<td>"+tmp.get(j)+"</td>");
}
strBuf.append("</tr>");
}
strBuf.append("</table>");
strBuf.append("<br>");
if(pageIndex>0)
{
strBuf.append("|<a href='"+pageUrlReal+"pageSize="+String.valueOf(pageSize)+"&pageIndex=0' onClick=\"commonSubmit("+this.formName+",this.href);return false;\">");
strBuf.append("<font color='red'>首页</font>");
strBuf.append("</a>|");
strBuf.append("<a href='"+pageUrlReal+"pageSize="+String.valueOf(pageSize)+"&pageIndex="+String.valueOf(pageIndex-1)+"' onClick=\"commonSubmit("+this.formName+",this.href);return false;\">");
strBuf.append("<font color='red'>上一页</font>");
strBuf.append("</a>|");
}
if(pageIndex<pageTotal-1)
{
strBuf.append("<a href='"+pageUrlReal+"pageSize="+String.valueOf(pageSize)+"&pageIndex="+String.valueOf(pageIndex+1)+"' onClick=\"commonSubmit("+this.formName+",this.href);return false;\">");
strBuf.append("<font color='red'>下一页</font>");
strBuf.append("</a>|");
strBuf.append("<a href='"+pageUrlReal+"pageSize="+String.valueOf(pageSize)+"&pageIndex="+String.valueOf(pageTotal-1)+"' onClick=\"commonSubmit("+this.formName+",this.href);return false;\">");
strBuf.append("<font color='red'>末页</font>");
strBuf.append("</a>|");
}
strBuf.append("<font color='red'>每页显示</font>");
strBuf.append("<input type=text name='pageSizeText' size=10 value="+pageSize+">");
strBuf.append("</input>");
strBuf.append("<font color='red'>行</font>");
//js脚本
strBuf.append("\n");
strBuf.append("<script language='JavaScript'>\n");
//提交翻页操作脚本
strBuf.append("function commonSubmit(formObject,url)"+"\n");
strBuf.append("{\n");
strBuf.append("formObject.action=url"+"\n");
//strBuf.append("alert(formObject.action)\n");
strBuf.append("formObject.submit();"+"\n");
strBuf.append("}"+"\n");
//如果选择类型为checkbox,增加全选的脚本
if(this.getSelectType() == OperateConst.SELECT_TYPE_CHECKBOX)
{
//行选择脚本(用于checkBox)
strBuf.append("function doSelectAll()"+"\n");
strBuf.append("{"+"\n");
strBuf.append("var ItemName = '"+this.selectItemName+"'"+"\n");
strBuf.append("var ItemObj ;\n");
strBuf.append("var i ;\n");
strBuf.append("for(i=0;i<"+this.formName+".length;i++)\n");
strBuf.append("{\n");
strBuf.append("if("+this.formName+".elements[i].name == '"+this.selectItemName+"')\n");
strBuf.append("{\n");
strBuf.append("ItemObj = "+this.formName+".elements[i];\n");
strBuf.append("if("+this.formName+".checkAll.checked == true)\n");
strBuf.append("{\n");
strBuf.append("ItemObj.checked = true;\n");
strBuf.append("}\n");
strBuf.append("else\n");
strBuf.append("{\n");
strBuf.append("ItemObj.checked = false;\n");
strBuf.append("}\n");
strBuf.append("}\n");
strBuf.append("}\n");
strBuf.append("}\n");
}
strBuf.append("</script>\n");
if(this.getFormName().equals(""))
{
strBuf.append("</form>");
}
return strBuf.toString();
}
else /*不支持数据库端分页*/
{
return getContentHtml(pm_iPageSize,pm_iPageIndex,pm_sSql,request,response);
}
}
//属性get/set方法
public String getFormName() {
return formName;
}
public void setFormName(String formName) {
this.formName = formName;
}
public String[] getContentTitle() {
return contentTitle;
}
public void setContentTitle(String[] contentTitle) {
this.contentTitle = contentTitle;
}
public String getSelectItemName() {
return selectItemName;
}
public void setSelectItemName(String selectItemName) {
this.selectItemName = selectItemName;
}
public int[] getSelectKeyArray() {
return selectKeyArray;
}
public void setSelectKeyArray(int[] selectKeyArray) {
this.selectKeyArray = selectKeyArray;
}
public int getSelectType() {
return selectType;
}
public void setSelectType(int selectType) {
this.selectType = selectType;
}
public boolean hasSelectItem() {
return hasSelectItem;
}
public void setHasSelectItem(boolean hasSelectItem) {
this.hasSelectItem = hasSelectItem;
}
public int getForwardType() {
return forwardType;
}
public void setForwardType(int forwardType) {
this.forwardType = forwardType;
}
public String getPageUrl() {
return pageUrl;
}
public void setPageUrl(String pageUrl) {
this.pageUrl = pageUrl;
}
public void setSelfForm(boolean isSelfForm) {
this.isSelfForm = isSelfForm;
}
public void setDataVector(Vector dataVector) {
this.dataVector = dataVector;
}
public void setCon(Connection con) {
this.con = con;
}
}
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -