不知道到底是没从数据库中取出数据还是后台数据没有传送到前台,实在晕了求各位朋友帮助 谢谢
<%@ page contentType="text/html; charset=GBK"%>
<%@ taglib uri="/WEB-INF/tlds/c-rt.tld" prefix="c"%>
<%@ taglib uri="/WEB-INF/tlds/fmt-rt.tld" prefix="fmt"%>
<%
    String path = request.getContextPath();
%>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=ISO-8859-1">
<link href="<%=path%>/css/main.css" rel="stylesheet" type="text/css">
<link href="<%=path%>/css/a.css" rel="stylesheet" type="text/css">
<title>用户信息列表</title>
<SCRIPT LANGUAGE="JavaScript" src="<%=path%>/common/js/prototype.js"></SCRIPT>
<SCRIPT LANGUAGE="JavaScript"
    src="<%=path%>/common/My97DatePicker/WdatePicker.js"></SCRIPT><SCRIPT LANGUAGE="JavaScript">//选中所有的复选框
function checkAll(name) {
    var el = document.getElementsByTagName('input');
    var len = el.length;
    for(var i=0; i<len; i++) {
        if((el[i].type=="checkbox") && (el[i].name==name))         
        {
            el[i].checked = true;
        }
    }
}// 取消所有的复选框
function clearAll(name) {
    var el = document.getElementsByTagName('input');     
    var len = el.length;     
    for(var i=0; i<len; i++) {
        if((el[i].type=="checkbox") && (el[i].name==name)) {             
            el[i].checked = false;
        }
    }
}
// 判断复选框是否选中了
function checkChckbox(){
    var obj=document.getElementsByName('idArray');
    for(var i=0;i<obj.length;i++){
        if(obj[i].checked)
        {
            return true;
        }
    }
}function searchUser(){
    $("refrush").value="true";
    $("userListForm").submit();
}function isnull(str) {
    if (str == null || str == "" || str == "undefine") {
        return true;
    }
    return false;
}
    function deleteUser(id){
        if(!isnull(id)){
            if(confirm("确定要删除此用户吗")){
                $("userListForm").action="${pageContext.request.contextPath}/deleteUser.action?id="+id;
            }else{  
                return false;
            }
        }else{
            if(checkChckbox()){
                if(confirm("确定要删除这些用户吗?")){
                    $("userListForm").action="${pageContext.request.contextPath}/deleteUser.action"; 
                }else{  
                    return false;
                }
            }else{
                alert("请选择用户!");
                return false;
            }
        }        $("userListForm").submit();
    }  
</script>
</head>
<body>    <form id="userListForm" name="userListForm" action="<%=path %>/searchUser.action" method="post">
        <span class="headline">
        <center>用户信息列表</center>
        <input type="hidden"
            id="refrush" name="refrush" value="false" />
            
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
        <tr>
          
          <td class="search" align="right" width="30%" nowrap>用户名:</td>
          <td class="search"><input type="text" id="user.userName" name="user.userName" value="${user.userName}" /></td>
          
          <td class="search" align="right" width="30%" nowrap>用户年龄:</td>
          <td class="search"><input type="text" id="user.age" name="user.age" value="${user.age}"/></td>
          
          <td class="search" align="right" width="30%" nowrap>用户性别:</td>
          <td class="search"><input type="text" id="user.sex" name="user.sex" value="${user.sex}" /></td>
       </tr>  
       
            <td class="search" width="30%" colspan="2">
      <table width="100%"> 
       <tr>
          <td width="100%" align="right" nowrap class="datacell"></td>
          <td><input class="btn" type="button" value="查询" onclick="javascript:searchUser();"/></td>
          <td><input class="btn" type="button" value="添加" onclick="window.location.href='<%=path%>/toEditUser.action';" /></td>
          <td><input class="btn" type="button" value="删除"  onclick="javascript:deleteUser('');"/></td>
       </tr>
       </table>
       </td>
       </table>
       
       
<div class="search"></div>
<table width="100%" border="0" cellpadding="3" cellspacing="0"
    bordercolor="#CCCCCC" style="border-collapse: collapse"
    class="tableCenter">
    <tr>
        <td colspan="3">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td class="dataFTop" align="left"><img
                    src="<%=path%>/images/frame1.gif" width="6" height="6" /></td>
                <td class="dataFTop" align="right"><img
                    src="<%=path%>/images/frame3.gif" /></td>
            </tr>
        </table>
        </td>
    </tr>
    <tr>
        <td class="dataFLeft1">&nbsp;</td>
        <td class="dataFBody">
        <table width="100%" cellspacing="1" cellpadding="0"
            class="dataTbBorder">
            <tr>
                <td class="dataTbHead" nowrap></td>
                <td class="dataTbHead" nowrap>序号</td>
                <td class="dataTbHead" nowrap>用户名</td>
                <td class="dataTbHead" nowrap>用户年龄</td>
                <td class="dataTbHead" nowrap>用户性别</td>
                <td class="dataTbHead" nowrap>操作</td>
            </tr>            <c:if test="${not empty userPage}">
                <c:set var="rownum"
                    value="${(userPage.currentPageNo-1)*userPage.pageSize}" />
                <c:forEach items="${userPage.dataList }" var="userList"
                    varStatus="index">
                    <c:set var="rownum" value="${rownum+1}" />
                    <tr>
                        <td class="dataTb2"><input type="checkbox" name="idArray"
                            id="idArray" style="border-width: 0; width: 15; height: 15"
                            value="${userList.id}"></td>
                        <td class="dataTb2">${rownum}</td>
                        <td class="dataTb2">${userList.userName }</td>
                        <td class="dataTb2">${userList.age }</td>
                        <td class="dataTb2">${userList.sex }</td>
                        <td class="dataTb2"><a
                            href="${pageContext.request.contextPath}/toEditUser.action?id=${userList.id }">
                        <img
                            src="${pageContext.request.contextPath}/images/edit_icon.gif"
                            title="编辑" border="0"> </a> <a
                            href="${pageContext.request.contextPath}/detailUser.action?id=${userList.id }">
                        <img
                            src="${pageContext.request.contextPath}/images/search_icon.gif"
                            title="查看" border="0"> </a><img style="cursor: hand"
                            src="${pageContext.request.contextPath}/images/remove.gif"
                            title="删除" border="0"
                            onclick="deleteUser('${userList.id}');"></td>
                    </tr>
                </c:forEach>
            </c:if>
        </table>
        </td>
        <td class="dataFRight1">&nbsp;</td>
    </tr>
    <tr>
        <td colspan="3">
        <table width="100%" border="0" cellspacing="0" cellpadding="0">
            <tr>
                <td class="dataFBottom" align="left"><img
                    src="<%=path%>/images/frame7.gif" /></td>
                <td class="dataFBottom" align="right"><img
                    src="<%=path%>/images/frame9.gif" /></td>
            </tr>
        </table>
        </td>
    </tr>
</table>
</form><jsp:include page="/common/PageController.jsp" flush="true">
    <jsp:param name="curPage" value="${userPage.currentPageNo}" />
    <jsp:param name="perPage" value="${userPage.pageSize}" />
    <jsp:param name="totalCnt" value="${userPage.totalCount}" />
    <jsp:param name="orderColumn" value="" />
    <jsp:param name="orderType" value="" />
</jsp:include></body>
</html>我觉得jsp页面应该没错误,错误应该再action和service层。用断点差错设置的断点跟本就没有到

解决方案 »

  1.   


    /**
     * 
     */
    package com.css.train.report.service.impl;import java.io.Serializable;
    import java.util.ArrayList;
    import java.util.List;import com.css.train.report.dao.UserDAO;
    import com.css.train.report.model.User;
    import com.css.train.report.service.UserService;
    import com.css.train.report.util.Page;
    import com.css.train.report.util.StringHelper;
    public class UserServiceImpl implements UserService {
        
        private UserDAO userDAO;
        
        public void setUserDAO(UserDAO userDAO){
            this.userDAO = userDAO;
        }
        
        private User user;    /* (non-Javadoc)
         * @see com.css.train.report.service.UserService#findAllUser(int)
         */
        public Page<User> findAllUser(int pageSize) {
            String hql = "from User user";
            return userDAO.pagedQuery(hql, 1, pageSize);
        }    /* (non-Javadoc)
         * @see com.css.train.report.service.UserService#getUserById(java.io.Serializable)
         */
        public User getUserById(Serializable id) {
            return userDAO.get(id);
        }    /* (non-Javadoc)
         * @see com.css.train.report.service.UserService#saveOrUpUser(com.css.train.report.model.User)
         */
        public void saveOrUpUser(User user) {
            this.userDAO.saveOrUpdate(user);    }    /* (non-Javadoc)
         * @see com.css.train.report.service.UserService#search(int, int, com.css.train.report.model.User)
         */
        public Page<User> search(int pageNo, int pageSize, User user) {
            String hql = "from User user where 1=1";
            List<Object> value = new ArrayList<Object>();
            if(StringHelper.isNotEmpty(user.getId())){
                hql += " and user.id like ?";
                value.add("%"+user.getId()+"%");
            }
            if(StringHelper.isNotEmpty(user.getUserName())){
                hql += " and user.username like ?";
                value.add("%"+user.getUserName()+"%");
            }
            return userDAO.pagedQuery(hql, pageNo, pageSize, value.toArray());
        }    /* (non-Javadoc)
         * @see com.css.train.report.service.UserService#removeUserById(java.io.Serializable)
         */
        public void removeUserById(Serializable id) {
            userDAO.removeById(id);    }    /* (non-Javadoc)
         * @see com.css.train.report.service.UserService#removeUser(java.lang.Object[])
         */
        public void removeUsers(Object... values) {
            if(values!=null&&values.length>0){
                for(int i=0;i<values.length;i++){
                    this.userDAO.removeById((Serializable) values[i]);
                }
            }    }    /**
         * @return the user
         */
        public User getUser() {
            return user;
        }    /**
         * @param user the user to set
         */
        public void setUser(User user) {
            this.user = user;
        }
        
        }
    上面是service层的
      

  2.   

    以下是action/**
     * 
     */
    package com.css.train.report.action;import com.css.train.report.model.User;
    import com.css.train.report.service.UserService;
    import com.css.train.report.util.Page;
    import com.css.train.report.util.SpringUtils;
    import com.opensymphony.xwork2.ActionSupport;
    public class UserAction extends ActionSupport {
        
        public static UserService userService;
        {
            userService = (UserService) SpringUtils.getContext(
                    "report").getBean("userService");
        }
        
        private User user;
        
        private String id;
        
        private int perPage=Page.getDefaultPageSize();
        
        private Page<User> userPage;
        
        private String idArray;
        
        private Integer curPage = 1;
        
        private boolean refrush;
        
        private String returnUrl;
        
        public UserAction(){
            
            user = new User();
        }
        
        public String findUser(){
            userPage = this.userService.findAllUser(perPage);
            return "list";
        }
        
        public String searchUser(){
            if (refrush) {
                curPage = 1;
                perPage = Page.getDefaultPageSize();
            }
            userPage = this.userService.search(curPage, perPage, user);
           return "list";   
        }    /**
         * @return the user
         */
        public User getUser() {
            return user;
        }    /**
         * @param user the user to set
         */
        public void setUser(User user) {
            this.user = user;
        }    /**
         * @return the id
         */
        public String getId() {
            return id;
        }    /**
         * @param id the id to set
         */
        public void setId(String id) {
            this.id = id;
        }    /**
         * @return the perPage
         */
        public int getPerPage() {
            return perPage;
        }    /**
         * @param perPage the perPage to set
         */
        public void setPerPage(int perPage) {
            this.perPage = perPage;
        }    /**
         * @return the userPage
         */
        public Page<User> getUserPage() {
            return userPage;
        }    /**
         * @param userPage the userPage to set
         */
        public void setUserPage(Page<User> userPage) {
            this.userPage = userPage;
        }    /**
         * @return the idArray
         */
        public String getIdArray() {
            return idArray;
        }    /**
         * @param idArray the idArray to set
         */
        public void setIdArray(String idArray) {
            this.idArray = idArray;
        }    /**
         * @return the curPage
         */
        public Integer getCurPage() {
            return curPage;
        }    /**
         * @param curPage the curPage to set
         */
        public void setCurPage(Integer curPage) {
            this.curPage = curPage;
        }    /**
         * @return the refrush
         */
        public boolean isRefrush() {
            return refrush;
        }    /**
         * @param refrush the refrush to set
         */
        public void setRefrush(boolean refrush) {
            this.refrush = refrush;
        }    /**
         * @return the returnUrl
         */
        public String getReturnUrl() {
            return returnUrl;
        }    /**
         * @param returnUrl the returnUrl to set
         */
        public void setReturnUrl(String returnUrl) {
            this.returnUrl = returnUrl;
        }
        
        
        }
      

  3.   

    "${userPage.totalCount}"后台怎么放的?
      

  4.   

    后台在工具包里有一个page的类文件。
    action和service都是用page的泛型定义的userpage然后再service中有方法
        public Page<User> search(int pageNo, int pageSize, User user) {
            String hql = "from User user where 1=1";
            List<Object> value = new ArrayList<Object>();
            if(StringHelper.isNotEmpty(user.getId())){
                hql += " and user.id like ?";
                value.add("%"+user.getId()+"%");
            }
            if(StringHelper.isNotEmpty(user.getUserName())){
                hql += " and user.username like ?";
                value.add("%"+user.getUserName()+"%");
            }
            return userDAO.pagedQuery(hql, pageNo, pageSize, value.toArray());
        }
    这里应该是从数据库中拿数据吧
      

  5.   


    我的意思是你在数据库拿出的这个Page对象 怎么放在在request 或 session 中的
      

  6.   

    楼主是不是td全部都出来了,值娶不到??
     我知道问题所在,因为你的userList 名字起太长了,struts2不知道怎么就不认识了,改短点就好了,或者直接   ${userName }也是可以的。
      

  7.   

    不是啊,这个jsp页面时我复制以前的项目的。以前用的都没问题,这次想自己尝试搭建ssh,然后就各种出错,应该不会是jsp的错误,jsp复制过来我只是改了下对应的数值。其他都没动。我觉得要么是service和action要么就是配置文件。其实我自己都说不清楚。各种乱