无法使用apachi瓷砖将两个lits传递给jsp

时间:2015-06-13 16:29:16

标签: hibernate jsp spring-mvc tiles

我正在使用带有Apache tile的spring mvc和hibernate.i将两个列表传递给jsp页面。但它是打印的,但没有任何东西打印。

我的控制器类如下:

if(userExists!=0){
            model.addAttribute("Maintabs",new Maintab());
             model.addAttribute("MaintabsList",loginService.listMaintabs());
             model.addAttribute("Subtabs",new Subtab());
             model.addAttribute("SubtabsList",loginService.listSubtab(userExists));


            return "redirect:/Loginsucess";
        }else{

             model.addAttribute("error", "ERROR : invaliduser !,Please Try Again!");

             return "loginform";
        }

jsp页面如下(menu.jsp):

<c:if test="${not empty SubtabsList}">
   <c:forEach var="ob"  items="${SubtabsList}">
    <c:out value="200"/>
<%--         <c:out value="${ob.maintab}"/> --%>
<%--         <c:out value="${ob.description}"/> --%>
<%--         <c:out value="${ob.ref}"/> --%>

   </c:forEach>

</c:if>

我想填充动态菜单。请帮助我使用jsp代码。

subtab modelclass:

package net.ABC.form;
// default package
// Generated Jun 7, 2015 11:03:29 AM by Hibernate Tools 4.0.0

import java.util.HashSet;
import java.util.Set;
import javax.persistence.Column;
import javax.persistence.Entity;
import javax.persistence.FetchType;
import javax.persistence.GeneratedValue;
import static javax.persistence.GenerationType.IDENTITY;
import javax.persistence.Id;
import javax.persistence.JoinColumn;
import javax.persistence.ManyToOne;
import javax.persistence.OneToMany;
import javax.persistence.Table;

/**
 * Subtab generated by hbm2java
 */
@Entity
@Table(name = "subtab", catalog = "ABC")
public class Subtab implements java.io.Serializable {

    private Integer subtabId;
    private Maintab maintab;
    private String description;
    private String ref;
    private Set<Authintication> authintications = new HashSet<Authintication>(0);

    public Subtab() {
    }

    public Subtab(Maintab maintab, String ref) {
        this.maintab = maintab;
        this.ref = ref;
    }

    public Subtab(Maintab maintab, String description, String ref,
            Set<Authintication> authintications) {
        this.maintab = maintab;
        this.description = description;
        this.ref = ref;
        this.authintications = authintications;
    }

    @Id
    @GeneratedValue(strategy = IDENTITY)
    @Column(name = "SubtabId", unique = true, nullable = false)
    public Integer getSubtabId() {
        return this.subtabId;
    }

    public void setSubtabId(Integer subtabId) {
        this.subtabId = subtabId;
    }

    @ManyToOne(fetch = FetchType.LAZY)
    @JoinColumn(name = "MainTabId", nullable = false)
    public Maintab getMaintab() {
        return this.maintab;
    }

    public void setMaintab(Maintab maintab) {
        this.maintab = maintab;
    }

    @Column(name = "description", length = 45)
    public String getDescription() {
        return this.description;
    }

    public void setDescription(String description) {
        this.description = description;
    }

    @Column(name = "ref", nullable = false, length = 45)
    public String getRef() {
        return this.ref;
    }

    public void setRef(String ref) {
        this.ref = ref;
    }

    @OneToMany(fetch = FetchType.LAZY, mappedBy = "subtab")
    public Set<Authintication> getAuthintications() {
        return this.authintications;
    }

    public void setAuthintications(Set<Authintication> authintications) {
        this.authintications = authintications;
    }

}

1 个答案:

答案 0 :(得分:0)

您正在添加属性并发送重定向。它将丢失您设置的所有信息。如果您重定向到该页面,它将显示正确。例如:

if(userExists!=0){
        model.addAttribute("Maintabs",new Maintab());
         model.addAttribute("MaintabsList",loginService.listMaintabs());
         model.addAttribute("Subtabs",new Subtab());
         model.addAttribute("SubtabsList",loginService.listSubtab(userExists));


        return "successPage";
    }else{

         model.addAttribute("error", "ERROR : invaliduser !,Please Try Again!");

         return "loginform";
    }

如果您想对数据进行重定向,可以使用HttpSession。

session.setAttribute("Maintabs",new Maintab());