首页 诗词 字典 板报 句子 名言 友答 励志 学校 网站地图
当前位置: 首页 > 教程频道 > JAVA > J2EE开发 >

action中拿不到页面发来的参数!解决方法

2013-10-31 
action中拿不到页面发来的参数!ACTION类@SuppressWarnings(serial)@Controller(ConditionQueryAction)

action中拿不到页面发来的参数!
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>&nbsp;&nbsp;&nbsp;</td>
      <td class="trTitle">客户编号:</td>
      <td><input type="text" name="clientId" id="textfield5" /></td>
      <td>&nbsp;&nbsp;&nbsp;</td>
      <td class="trTitle">电&nbsp;&nbsp;话:</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>&nbsp;</td>
      <td class="trTitle">联系人姓名</td>
      <td><input type="text" name="linkmanName" id="textfield6" /></td>
      <td>&nbsp;</td>
      <td class="trTitle">简&nbsp;&nbsp;拼:</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>



js

function gotos(i){
alert(i); //正常显示页面加1后的数值
theform.action = "querys?page="+i;
theform.submit();
}
分页 jsp
[解决办法]
是你page值在action没有拿到? 
[解决办法]
可定没有啊 楼主的page都已经写到 form表单传值过去了  不是对应struts属性 
你后台获取只能获取 getRequest.getParmeter("page");
你是把它做为一个参数传递过去了 而不是对应strtus机制直接引用和赋值 
[解决办法]
应该在你的form 里面定义一个name=page 的input。然后你用js提交action的时候把这个值赋上。
function gotos(i){
        alert(i); //正常显示页面加1后的数值
        theform.page.value=i;//这个时候form应该能拿到
        theform.action = "querys;
        theform.submit();
        }
[解决办法]
HttpServletRequest request=ServletActionContext.getRequest();
request.getParmeter("page"); 这样取值好了

热点排行