Java论坛网»Java技术»我写的关于struts的问题

我写的关于struts的问题

问?:
我是用Bean来处理的,以前是在JSP+Bean里面用的没有问题,我现在那到struts里面出了问题

这是控制分页的Bean

package com.cacrm.common;

import java.util.List;
import java.util.ArrayList;

public class PageControl{
private int curpage; //当前页页号
private int nextpage;//下一页页号
private int start;//本页开始数据编号
private int end;//本页结束数据编号+1
private int totalpage;//总计页数
private int totalnum;//总记录数
private int prepage;//上一页页号

private int int_num=2;//每页记录数
private int temp_curpage;//临时当前页
private int temp_start;//临时本页开始数据编号
private int temp_end;//临时本页结束数据编号+1
private int temp_totalnum;//临时总记录数
private int temp_totalpage;//临时总计页数

/**
* pcFindAll 根据页号和所有的记录数,返回该页要显示的记录
*
* @param currpage String 要显示的页号
* @param allList List 所有记录的list
* @return List 返回选定页的记录存放的ArrayList
*/
public List pcFindAll(String currpage,List allList){
List pcList=new ArrayList();
int int_num=this.getInt_num();
int curr=Integer.parseInt(currpage);
this.init(curr,allList.size());
int end_num=curr*int_num;
if(end_num>allList.size()){
end_num=allList.size();
}
for(int i=(curr-1)*int_num;i<end_num;i++){
pcList.add(allList.get(i));
}
return pcList;
}

public void init(int curpage,int totalnum){
temp_totalnum=totalnum;
if(curpage>1){
if(curpage>(int)Math.ceil((double)totalnum/(double)int_num)){
temp_curpage=(int)Math.ceil((double)totalnum/(double)int_num);
}
else{
temp_curpage=curpage;
}
}
else{
temp_curpage=1;
}
temp_start = (temp_curpage - 1) * int_num+1;
temp_end = temp_curpage * int_num;
if (temp_end > temp_totalnum) {
temp_end=temp_totalnum;
}

temp_totalpage=(int)Math.ceil((double)totalnum/(double)int_num);

setCurpage();
setNextpage();
setStart();
setEnd();
setTotalpage();
setTotalnum();
setPrepage();

}

public void setCurpage() {
this.curpage = temp_curpage;
}

public void setNextpage() {
if(temp_curpage+1>temp_totalpage){
nextpage=curpage;
}
else{
nextpage=temp_curpage+1;
}
}

public void setStart() {
this.start = temp_start;
}

public void setEnd() {
this.end = temp_end;
}

public void setTotalpage() {
this.totalpage = temp_totalpage;
}

public void setTotalnum() {
this.totalnum = temp_totalnum;
}

public void setPrepage() {
if(temp_curpage-1<1){
prepage=temp_curpage;
}
else{
prepage=temp_curpage-1;
}
}


public int getCurpage() {
return curpage;
}
public int getNextpage() {
return nextpage;
}

public int getStart() {
return start;
}

public int getEnd() {
return end;
}

public int getTotalpage() {
return totalpage;
}

public int getTotalnum() {
return totalnum;
}

public int getPrepage() {
return prepage;
}

public int getInt_num() {
return int_num;
}

}

action


ArrayList safetyList=(ArrayList)pc.pcFindAll(currpage,list);
System.out.println(safetyList.size());
request.setAttribute("safetyList",safetyList);
int nowPage = pc.getCurpage();

request.setAttribute("list",list);
request.setAttribute("jibie",jibie);


jsp

</table>
<table border="0" width="98%" cellpadding="0" cellspacing="0" align="center">
<tr>
<td height="40">&nbsp;</td>
</tr>
<tr align="center">
<td align="right"><a href="../../dept.do?method=findAll" onclick="gotoPage(1)">[第一页]</a>|<a href="../../dept.do?method=findAll" onclick="gotoPage(<%=pc.getPrepage()%>)">[上一页]</a>|<a href="../../dept.do?method=findAll" onclick="gotoPage(<%=pc.getNextpage()%>)">[下一页]</a>|<%if(pc.getTotalpage()==0){%><a href="../../dept.do?method=findAll" onclick="gotoPage(1)">[最后一页]</a><%}else{%><a href="../../dept.do?method=findAll" onclick="gotoPage(<%=pc.getTotalpage()%>)">[最后一页]</a><%}%>
</td>

</table>

<script language="javascript">
// batchDelete(key);

function gotoPage(currpage)
{
alert(currpage);
form1.currpage.value = currpage;
form1.submit();
}

</script>


我现在没有办法让每次点“下一页”的时候取出页数,有什么好办法
答!: 1:
form1.currpage.value = currpage;

这个表单元素通过request.getParameter得不到吗
答!: 2:
我现在在action里面把
request.setAttribute("currpage",currpage); 现在currpage=1
在JSP
currpage=(String)request.getAttribute("currpage");
System.out.println("currpage="+currpage);
可以取出来,但是
form1.currpage.value = currpage;
还是得不到
答!: 3:
学习,我也正在学习JSP,估计和楼主的进度差不多少,关注!
答!: 4:
是我的问题有问题,还是什么原因,为什么没有人回答那
答!: 5:
为什么不用Hibernate的分页控制功能,或者直接去调用微软的三个未公开的存储过程sp_cursoropen、sp_cursorfetch、sp_cursorclose呢?
答!: 6:
我公司的项目只让用struts没有用别的东西,还有就是我只会struts
答!: 7:
帮帮忙吧

相关JAVA教程:
请问如何判断按钮被按下和其需执行的操作
把weblogic移到JBoss上面的方法。
有没有办法知道调用EJB的客户端的IP地址?
各位大侠帮哈我!!!
求关于怎么改变界面的肤色方案
有人用过ireport生成excel报表吗?
【求助】我使用JAVA JDBC的批量提交插入数据遇到异常(一条违反约束的信息),其后的插入无法进行
利用dom4j的xpath读取子节点的问题
如何table表导出为excel表
在struts 中如何用FileUpload 的组件呢?
struts + ajax的后台问题
spring+hibernate连接数据库问题