ACTION类@SuppressWarnings("serial")
@Controller("ConditionQueryAction")
// 指定该类的对象在spring容器中的作用域为prototype
@Scope("prototype")
@Transactional
public class ConditionQueryAction extends ActionSupport implements ModelDriven<Client>{
@Resource
private ClientDao clientdao;
private Client client;
private Pager pager;
private int page;
public Client getModel() {
if(client == null){
client=new Client();
}
return client;
}
//不定条件查询 将返回的pagers对象 传送到页面
public String execute(){
System.out.println("page1是======="+page);//这里有问题 每次不管点击下一页 还是最后一页 总是显示 page1是======= 0 !!
if(page==0)
page=1;
pager = clientdao.query(getModel(),page,5);
ActionContext.getContext().put("pager", pager);
ActionContext.getContext().put("models", getModel());
return SUCCESS;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}jsp<form action="querys" method="post" name="theform">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="trTitle">单位名称:</td>
<td><label for="textfield"></label>
<input type="text" name="clientName" id="textfield" value="${models.clientName}"/></td>
<td> </td>
<td class="trTitle">客户编号:</td>
<td><input type="text" name="clientId" id="textfield5" /></td>
<td> </td>
<td class="trTitle">电 话:</td>
<td><label for="textfield2"></label>
<input type="text" name="telphone" id="textfield2" /></td>
</tr>
<tr>
<td class="trTitle">客户分类:</td>
<td><label for="select"></label>
<select name="clientType" id="select">
<option value="0">托运客户</option>
<option value="1">收货客户</option>
</select></td>
<td> </td>
<td class="trTitle">联系人姓名</td>
<td><input type="text" name="linkmanName" id="textfield6" /></td>
<td> </td>
<td class="trTitle">简 拼:</td>
<td><input type="text" name="spellBJDX" id="textfield4" /></td>
</tr>
</table>
<input type="submit" name="button" id="button" value="查询" class="btn" />
<input type="reset" name="button2" id="button2" value="重置" class="btn"/>
</form>分页<td colspan="8" align="right">
<div >
总条记录${pager.rowCount} 每页${pager.pageSize}条 当前第${pager.page}/${pager.pageCount}页
<c:choose>
<c:when test="${ pager.first }">首页 | 上一页 | </c:when>
<c:otherwise><a href='' onclick="gotos(1)">首页</a> | <a href="" onclick="gotos(${pager.page - 1 }")>上一页</a> | </c:otherwise>
</c:choose>
<c:choose>
<c:when test="${ pager.last }"> 下一页 | 尾页</c:when>
<c:otherwise><a href='' onclick="gotos(${pager.page+1})"> 下一页</a> | <a href='' onclick="gotos(${pager.pageCount })">尾页</a></c:otherwise>
</c:choose>
</td>jsfunction gotos(i){
alert(i); //正常显示页面加1后的数值
theform.action = "querys?page="+i;
theform.submit();
}
分页jsp
@Controller("ConditionQueryAction")
// 指定该类的对象在spring容器中的作用域为prototype
@Scope("prototype")
@Transactional
public class ConditionQueryAction extends ActionSupport implements ModelDriven<Client>{
@Resource
private ClientDao clientdao;
private Client client;
private Pager pager;
private int page;
public Client getModel() {
if(client == null){
client=new Client();
}
return client;
}
//不定条件查询 将返回的pagers对象 传送到页面
public String execute(){
System.out.println("page1是======="+page);//这里有问题 每次不管点击下一页 还是最后一页 总是显示 page1是======= 0 !!
if(page==0)
page=1;
pager = clientdao.query(getModel(),page,5);
ActionContext.getContext().put("pager", pager);
ActionContext.getContext().put("models", getModel());
return SUCCESS;
}
public int getPage() {
return page;
}
public void setPage(int page) {
this.page = page;
}
}jsp<form action="querys" method="post" name="theform">
<table border="0" cellspacing="0" cellpadding="0">
<tr>
<td class="trTitle">单位名称:</td>
<td><label for="textfield"></label>
<input type="text" name="clientName" id="textfield" value="${models.clientName}"/></td>
<td> </td>
<td class="trTitle">客户编号:</td>
<td><input type="text" name="clientId" id="textfield5" /></td>
<td> </td>
<td class="trTitle">电 话:</td>
<td><label for="textfield2"></label>
<input type="text" name="telphone" id="textfield2" /></td>
</tr>
<tr>
<td class="trTitle">客户分类:</td>
<td><label for="select"></label>
<select name="clientType" id="select">
<option value="0">托运客户</option>
<option value="1">收货客户</option>
</select></td>
<td> </td>
<td class="trTitle">联系人姓名</td>
<td><input type="text" name="linkmanName" id="textfield6" /></td>
<td> </td>
<td class="trTitle">简 拼:</td>
<td><input type="text" name="spellBJDX" id="textfield4" /></td>
</tr>
</table>
<input type="submit" name="button" id="button" value="查询" class="btn" />
<input type="reset" name="button2" id="button2" value="重置" class="btn"/>
</form>分页<td colspan="8" align="right">
<div >
总条记录${pager.rowCount} 每页${pager.pageSize}条 当前第${pager.page}/${pager.pageCount}页
<c:choose>
<c:when test="${ pager.first }">首页 | 上一页 | </c:when>
<c:otherwise><a href='' onclick="gotos(1)">首页</a> | <a href="" onclick="gotos(${pager.page - 1 }")>上一页</a> | </c:otherwise>
</c:choose>
<c:choose>
<c:when test="${ pager.last }"> 下一页 | 尾页</c:when>
<c:otherwise><a href='' onclick="gotos(${pager.page+1})"> 下一页</a> | <a href='' onclick="gotos(${pager.pageCount })">尾页</a></c:otherwise>
</c:choose>
</td>jsfunction gotos(i){
alert(i); //正常显示页面加1后的数值
theform.action = "querys?page="+i;
theform.submit();
}
分页jsp
但是你看我的js里 的alert 显示的1
但是表单提交到action 在里面拿到的 page是0!
你后台获取只能获取 getRequest.getParmeter("page");
你是把它做为一个参数传递过去了 而不是对应strtus机制直接引用和赋值
function gotos(i){
alert(i); //正常显示页面加1后的数值
theform.page.value=i;//这个时候form应该能拿到
theform.action = "querys;
theform.submit();
}
request.getParmeter("page"); 这样取值好了
依然是0 而且我后面这样写theform.action ="querys?page="+i;page就相当于那么属性吧
theform.submit();HttpServletRequest request=ServletActionContext.getRequest();
request.getParmeter("page"); 这样拿到的是null?
CLient ?这是一个modle啊
request.getParmeter("page"); 这样取值好了如果要对应struts里面的page变量,你要在页面写一个name="page" value等于page值的一个input hidden元素
System.out.println(pager.getPage());
pager是空啊 怎么pager.getPage
pager是空啊 怎么pager.getPage好吧 看错了
你点下一页的时候 alert出来的值是多少
pager是空啊 怎么pager.getPage好吧 看错了
你点下一页的时候 alert出来的值是多少2
pager是空啊 怎么pager.getPage好吧 看错了
你点下一页的时候 alert出来的值是多少2 function gotos(i){
theform.action = "querys?page=1";
theform.submit();
}
路径写死看看
pager是空啊 怎么pager.getPage好吧 看错了你点下一页的时候 alert出来的值是多少2 function gotos(i){
theform.action = "querys?page=1";
theform.submit();
}
路径写死看看
不行
method="post" 你改用"get"方法提交。
pager是空啊 怎么pager.getPage好吧 看错了你点下一页的时候 alert出来的值是多少2 function gotos(i){
theform.action = "querys?page=1";
theform.submit();
}
路径写死看看
不行是什么不行?后台输出是0?还是没输出?
page页面上也没有name="page"的表单,page当然是0了。