legend_jhz
2008-11-11 15:37
浏览 261
已采纳

ssh分页问题

action定义如下:
[code="java"]
public class CRMGuestAction extends DispatchAction {
private CRMDao crmDao;
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaValidatorForm f = (DynaValidatorForm) form;

JzGuestbook guestbook = new JzGuestbook();
guestbook.setCpcode(cpcode);
guestbook.setAddress(address);
guestbook.setContel(contel);
guestbook.setContect(contect);
guestbook.setTel(tel);
guestbook.setRegisternumber(registernumber);

List all = null;
int currentPage = 1;
int lineSize = 3;
int allRecorders = 0;
try {
currentPage = Integer.parseInt(request.getParameter("cp"));
} catch (Exception e) {
}
try {
crmDao.addGuestbook(guestbook);
allRecorders = crmDao.getGuestbookTotal();
all = crmDao.getAllGuestbook(currentPage, lineSize);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("currentPage", currentPage);
request.setAttribute("lineSize", lineSize);
request.setAttribute("allRecorders", allRecorders);
request.setAttribute("jspUrl", "cRMGuest.do");
request.setAttribute("all", all);
return mapping.findForward("indexguest");
}

public ActionForward selectall(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) {
    System.out.println("here");
    List all = null;
    int currentPage = 1;
    int lineSize = 3;
    int allRecorders = 0;
    try {
        System.out.println(request.getParameter("cp"));
        currentPage = Integer.parseInt(request.getParameter("cp"));
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        allRecorders = crmDao.getGuestbookTotal();
        all = crmDao.getAllGuestbook(currentPage, lineSize);
    } catch (Exception e) {
        e.printStackTrace();
    } 
    request.setAttribute("currentPage", currentPage);
    request.setAttribute("lineSize", lineSize);
    request.setAttribute("allRecorders", allRecorders);
    request.setAttribute("jspUrl", "cRMGuest.do");
    request.setAttribute("all", all);
    return mapping.findForward("indexguest");
}

public void setCrmDao(CRMDao crmDao) {
    this.crmDao = crmDao;
}

}

[/code]

这页是jsp页面如下:
[code="java"]



[color=red] onsubmit="return validateCRMGuestForm(this)">


客户名称:

/html:text



联系人:

/html:text



联系电话:

/html:text



地址:

/html:text










/html:form
        <table border="0" width="100%">
            <tr>
                <td>
                    联系人
                </td>
                <td>
                    联系电话
                </td>
                </tr>
            <c:forEach items="${requestScope['all']}" var="user">
            <tr>
                <td>
                    <c:out value="${user.contect}"></c:out>
                </td>
                <td>
                    <c:out value="${user.contel}"></c:out>
                </td>
            </tr>
            </c:forEach>
        </table>
    <jsp:include page [color=red]="/split_page.jsp">[/color]
    <jsp:param name="lineSize" value="${lineSize}" />
    <jsp:param name="jspUrl" value="${jspUrl}" />
    <jsp:param name="allRecorders" value="${allRecorders}" />
    <jsp:param name="currentPage" value="${currentPage}" />
    <jsp:param name="searchFlag" value="F" />
    </jsp:include>
</body>

[/code]
split_page.jsp为:
[code="java"]
<%@ page contentType="text/html;charset=utf-8"%>
<%
String jspUrl = null ;
int lineSize = 10 ;
int currentPage = 1 ;
int pageSize = 0 ;
int allRecorders = 0;
String keyWord = null ;
String searchFlag = "F" ;
%>
<%
jspUrl = request.getParameter("jspUrl") ;
keyWord = request.getParameter("keyWord") ;
searchFlag = request.getParameter("searchFlag") ;
try
{
[color=red]lineSize = Integer.parseInt(request.getParameter("lineSize")) ;
currentPage = Integer.parseInt(request.getParameter("currentPage")) ;
allRecorders = Integer.parseInt(request.getParameter("allRecorders")) ;//会产生java.lang.NumberFormatException: For input string: "" [/color] }
catch(Exception e)
{
// }
%>
<% pageSize = (allRecorders+lineSize-1)/lineSize ;
%>

function openPage(curpage) { document.spage.cp.value = curpage ; document.spage.submit() ; } function selOpenPage() { document.spage.cp.value = document.spage.selpage.value ; document.spage.submit() ; } function change() { if(document.spage.kw.value!="") { document.spage.status.value = "selectlike" ; } }

[color=red]

">/*产生url地址*/[/color]<%
if("T".equals(searchFlag))
{
%>
输入查询关键字:">





<%
}
%>
<%
if(allRecorders>0)
{
%>

>

<%=currentPage%>
/
<%=pageSize%>
跳转到

<%
for(int x=1;x<=pageSize;x++)
{
%>
input="/crm/cRMGuest.jsp"
name="cRMGuestForm"
parameter="method"
path="/cRMGuest"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" >



[/code]
现在是提交好信息时会列出第一页信息,点击下一页时,uri的地址:http://localhost:8088/Demo/cRMGuest.do?method=selectall&cp=2&selpage=1是正确的,但是第二页的信息却显示不出来,同时我在CRMGuestAction的seletall中标注了断点以及起始处写上输出标识,但是在点下一页时单步调试时并没有运行到那里就停止了,是我那个地方设置的不对?

[b]问题补充:[/b]
action定义如下:
[code="java"]
public class CRMGuestAction extends DispatchAction {
private CRMDao crmDao;
public ActionForward save(ActionMapping mapping, ActionForm form,
HttpServletRequest request, HttpServletResponse response) {
DynaValidatorForm f = (DynaValidatorForm) form;

JzGuestbook guestbook = new JzGuestbook();
guestbook.setCpcode(cpcode);
guestbook.setAddress(address);
guestbook.setContel(contel);
guestbook.setContect(contect);
guestbook.setTel(tel);
guestbook.setRegisternumber(registernumber);

List all = null;
int currentPage = 1;
int lineSize = 3;
int allRecorders = 0;
try {
currentPage = Integer.parseInt(request.getParameter("cp"));
} catch (Exception e) {
}
try {
crmDao.addGuestbook(guestbook);
allRecorders = crmDao.getGuestbookTotal();
all = crmDao.getAllGuestbook(currentPage, lineSize);
} catch (Exception e) {
e.printStackTrace();
}
request.setAttribute("currentPage", currentPage);
request.setAttribute("lineSize", lineSize);
request.setAttribute("allRecorders", allRecorders);
request.setAttribute("jspUrl", "cRMGuest.do");
request.setAttribute("all", all);
return mapping.findForward("indexguest");
}

public ActionForward selectall(ActionMapping mapping, ActionForm form,
        HttpServletRequest request, HttpServletResponse response) {
    System.out.println("here");
    List all = null;
    int currentPage = 1;
    int lineSize = 3;
    int allRecorders = 0;
    try {
        System.out.println(request.getParameter("cp"));
        currentPage = Integer.parseInt(request.getParameter("cp"));
    } catch (Exception e) {
        e.printStackTrace();
    }
    try {
        allRecorders = crmDao.getGuestbookTotal();
        all = crmDao.getAllGuestbook(currentPage, lineSize);
    } catch (Exception e) {
        e.printStackTrace();
    } 
    request.setAttribute("currentPage", currentPage);
    request.setAttribute("lineSize", lineSize);
    request.setAttribute("allRecorders", allRecorders);
    request.setAttribute("jspUrl", "cRMGuest.do");
    request.setAttribute("all", all);
    return mapping.findForward("indexguest");
}

public void setCrmDao(CRMDao crmDao) {
    this.crmDao = crmDao;
}

}

[/code]

这页是jsp页面如下:
[code="java"]



[color=red] onsubmit="return validateCRMGuestForm(this)">


客户名称:

/html:text



联系人:

/html:text



联系电话:

/html:text



地址:

/html:text










/html:form
        <table border="0" width="100%">
            <tr>
                <td>
                    联系人
                </td>
                <td>
                    联系电话
                </td>
                </tr>
            <c:forEach items="${requestScope['all']}" var="user">
            <tr>
                <td>
                    <c:out value="${user.contect}"></c:out>
                </td>
                <td>
                    <c:out value="${user.contel}"></c:out>
                </td>
            </tr>
            </c:forEach>
        </table>
    <jsp:include page [color=red]="/split_page.jsp">[/color]
    <jsp:param name="lineSize" value="${lineSize}" />
    <jsp:param name="jspUrl" value="${jspUrl}" />
    <jsp:param name="allRecorders" value="${allRecorders}" />
    <jsp:param name="currentPage" value="${currentPage}" />
    <jsp:param name="searchFlag" value="F" />
    </jsp:include>
</body>

[/code]
split_page.jsp为:
[code="java"]
<%@ page contentType="text/html;charset=utf-8"%>
<%
String jspUrl = null ;
int lineSize = 10 ;
int currentPage = 1 ;
int pageSize = 0 ;
int allRecorders = 0;
String keyWord = null ;
String searchFlag = "F" ;
%>
<%
jspUrl = request.getParameter("jspUrl") ;
keyWord = request.getParameter("keyWord") ;
searchFlag = request.getParameter("searchFlag") ;
try
{
[color=red]lineSize = Integer.parseInt(request.getParameter("lineSize")) ;
currentPage = Integer.parseInt(request.getParameter("currentPage")) ;
allRecorders = Integer.parseInt(request.getParameter("allRecorders")) ;//会产生java.lang.NumberFormatException: For input string: "" [/color] }
catch(Exception e)
{
// }
%>
<% pageSize = (allRecorders+lineSize-1)/lineSize ;
%>

function openPage(curpage) { document.spage.cp.value = curpage ; document.spage.submit() ; } function selOpenPage() { document.spage.cp.value = document.spage.selpage.value ; document.spage.submit() ; } function change() { if(document.spage.kw.value!="") { document.spage.status.value = "selectlike" ; } }

[color=red]

">/*产生url地址*/[/color]<%
if("T".equals(searchFlag))
{
%>
输入查询关键字:">





<%
}
%>
<%
if(allRecorders>0)
{
%>

>

<%=currentPage%>
/
<%=pageSize%>
跳转到

<%
for(int x=1;x<=pageSize;x++)
{
%>
input="/crm/cRMGuest.jsp"
name="cRMGuestForm"
parameter="method"
path="/cRMGuest"
scope="request"
type="org.springframework.web.struts.DelegatingActionProxy" >



[/code]
现在是提交好信息时会列出第一页信息,点击下一页时,uri的地址:http://localhost:8088/Demo/cRMGuest.do?method=selectall&cp=2&selpage=1是正确的,但是第二页的信息却显示不出来,同时我在CRMGuestAction的seletall中标注了断点以及起始处写上输出标识,但是在点下一页时单步调试时并没有运行到那里就停止了,是我那个地方设置的不对? [color=red]">[/color]这是生成的地址,地址没问题是正确的。

[b]问题补充:[/b]
查询关键字还没有涉及,这个应该不是这方面的问题。
[b]问题补充:[/b]
[color=red]这个问题的关键是生成的url是正确的,但是没有去跳转到action中,是不是配置的问题?我的工程目录如下:
web-root
--web-inf
--crm
--cRMGuest.jsp
--single-page.jsp[/color]
[b]问题补充:[/b]
[color=red]我按照您说的输入url:http://localhost:8088/Demo/cRMGuest.do?method=selectall&cp=2&selpage=1,没有显示,所以我觉得可能配置有问题,我能显示的第一个页面,因为我首先要提交一些信息后,我用的jsp中action的地址是/cRMGuest.do?method=save,然后再进入的时候,我把url换为url:http://localhost:8088/Demo/cRMGuest.do?method=selectall&cp=2&selpage=1就不保存那些提交的信息了。[/color]

  • 点赞
  • 写回答
  • 关注问题
  • 收藏
  • 邀请回答

10条回答 默认 最新

  • catstiger 2008-11-11 16:55
    已采纳

    你直接在浏览器上输入http://localhost:8088/Demo/cRMGuest.do?method=selectall&cp=2&selpage=1看看行不行。

    点赞 打赏 评论
  • catstiger 2008-11-11 15:55

    openPage函数没有为method赋值?
    javascript还是用标准的DOM操作比较好。
    感觉是客户端代码,包括js和<%%>中的代码有问题,你的jsp写的太乱了。

    点赞 打赏 评论
  • bohemia 2008-11-11 16:24

    1.你的问题估计是这样:

    输入查询关键字:">

    keyWord是Null,看不到你什么地方提交过这个变量;

    修改成:

    输入查询关键字:">

    2.你的JSP太乱了.
    如果非常喜欢用JSP,就写规整点,否则后面的维护,就是在煎熬; 呵呵..煎熬的日子不好受..希望能提前看到.

    点赞 打赏 评论
  • bohemia 2008-11-11 16:24

    输入查询关键字:">

    不好意思少写了个'='

    点赞 打赏 评论
  • catstiger 2008-11-11 16:52

    先调整一下客户端代码把,估计配置什么的不会有问题,因为第一次不是能正常执行吗?而且,第二页的时候都没有进action里面。
    客户端代码太乱了,看的头晕呀,在我们这里<%%>是不允许使用的,js代码也尽量弄到.js文件里面。如果你使用Ext或者GT_Grid之类的js组件,那么代码能少很多整齐很多很多的。

    点赞 打赏 评论
  • yuanyeekong1985 2008-11-11 17:01

    你直接在浏览器上输入http://localhost:8088/Demo/cRMGuest.do?method=selectall&cp=2&selpage=1 可以这样试下,如果不等就用断点调试下,问题不大

    点赞 打赏 评论
  • yuanyeekong1985 2008-11-11 17:05

    private CRMDao crmDao;

    你的这个类是怎么处理的?

    点赞 打赏 评论
  • yuanyeekong1985 2008-11-11 17:08

    actionForm中到了吗?

    点赞 打赏 评论
  • catstiger 2008-11-11 17:18

    惨了,肯定是配置问题。可是我没有勇敢struts1和spring整合,struts1都是直接用的,想获得spring的bean就在父类里面加一个getBean(String beanId)方法,我建议你不用DelegatingActionProxy,然后试试,bean的获得用Spring的WebApplicationContextUtils。还有,Action配置里面的Attribute属性我也从来没有用过,要不也去掉? :(

    点赞 打赏 评论
  • catstiger 2008-11-11 17:19

    勇敢=用过,怎么不能修改回复呀。

    点赞 打赏 评论

相关推荐 更多相似问题