在写一个方法时遇到了这个问题废话不多说,直接上出问题的方法的代码
以下是struts1 的action的关于这个出问题的方法的代码:List categoryList = new ArrayList();//下面是调用获取所有商品类别的方法,该方法含有树的递归,9是树的根节点,categoryList当做参数传进去添加值
categoryManager.getAllCategories(categoryList, 9);
//把categoryList通过Session传到jsp上
//(顺便问个问题,要把这个链表在jsp页面上获取并显示值,有没有别的办法,我觉得这个不好,我用的是struts1)
request.getSession().setAttribute("categoryList", categoryList);以下是Hibernate的代码:
//以下是上面调用的获取所有类别的方法/**
* 用递归获取所有的类别
* @param categoryList 把链表传进来用于递归添加值
* @param rootid 起始结点
*/
public void getAllCategories(List categoryList, int rootid) {
List resultList = this.getHibernateTemplate().find("select c from Category c where c.parentCategory.categoryid = " + rootid);
for(int i = 0; i < resultList.size(); i++) {
Category category = (Category)resultList.get(i);
//给传进来的链表添加值
categoryList.add(category);
//如果不是叶子节点,则递归继续
if(!category.isLeaf()) {
getAllCategories(categoryList, category.getCategoryid());
}
}
}JSP获取链表数据的代码如下<c:forEach items="${ categoryList}" var="category" >
<tr>
<td>
<!-- 下面这小段是用来显示出层次感, grade参数表示该节点是第几层 -->
<c:forEach begin="2" end="${ category.grade}">
<c:out value="---" />
</c:forEach> <c:out value="${ category.categoryid}" />
</td>
<td>
<c:out value="${ category.name}" />
</td>
<td>
<!-- 显示父节点的名称 -->
<c:out value="${ category.parentCategory.name}" />
</td>
<td>
<c:out value="${ category.desc}" />
</td>
</tr>
</c:forEach>
上面就是相关的代码,我的配置文件应该没问题,因为别的方法都没出现该问题,请各位帮忙下,时间紧迫啊
以下是struts1 的action的关于这个出问题的方法的代码:List categoryList = new ArrayList();//下面是调用获取所有商品类别的方法,该方法含有树的递归,9是树的根节点,categoryList当做参数传进去添加值
categoryManager.getAllCategories(categoryList, 9);
//把categoryList通过Session传到jsp上
//(顺便问个问题,要把这个链表在jsp页面上获取并显示值,有没有别的办法,我觉得这个不好,我用的是struts1)
request.getSession().setAttribute("categoryList", categoryList);以下是Hibernate的代码:
//以下是上面调用的获取所有类别的方法/**
* 用递归获取所有的类别
* @param categoryList 把链表传进来用于递归添加值
* @param rootid 起始结点
*/
public void getAllCategories(List categoryList, int rootid) {
List resultList = this.getHibernateTemplate().find("select c from Category c where c.parentCategory.categoryid = " + rootid);
for(int i = 0; i < resultList.size(); i++) {
Category category = (Category)resultList.get(i);
//给传进来的链表添加值
categoryList.add(category);
//如果不是叶子节点,则递归继续
if(!category.isLeaf()) {
getAllCategories(categoryList, category.getCategoryid());
}
}
}JSP获取链表数据的代码如下<c:forEach items="${ categoryList}" var="category" >
<tr>
<td>
<!-- 下面这小段是用来显示出层次感, grade参数表示该节点是第几层 -->
<c:forEach begin="2" end="${ category.grade}">
<c:out value="---" />
</c:forEach> <c:out value="${ category.categoryid}" />
</td>
<td>
<c:out value="${ category.name}" />
</td>
<td>
<!-- 显示父节点的名称 -->
<c:out value="${ category.parentCategory.name}" />
</td>
<td>
<c:out value="${ category.desc}" />
</td>
</tr>
</c:forEach>
上面就是相关的代码,我的配置文件应该没问题,因为别的方法都没出现该问题,请各位帮忙下,时间紧迫啊
<c:out value="${ category.parentCategory.name}" />
这一句是要查出父节点的名称 但是session已关闭 所以报异常了你研究一下open session in view 不明白的话再q我 715292414
但是我web.xml里有配置<filter>
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
</filter>
<filter-mapping>
<filter-name>hibernateFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping> 为什么还会这样,我要用到<c:out value="${ category.parentCategory.name}" />,该怎么做
你得好好去看看啊!
<filter-name>hibernateFilter</filter-name>
<filter-class>org.springframework.orm.hibernate3.support.OpenSessionInViewFilter</filter-class>
<init-param>
<param-name>flushMode</param-name>
<param-value>AUTO</param-value>
</init-param>
</filter>试试
貌似写得很详细,不知道有没有帮助