我的jsp页面中的Struts 2会话访问问题

时间:2012-11-21 02:24:17

标签: hibernate session struts2 ognl

我有一个JSP页面,我希望以这种方式显示会话中的一些信息

<div>Fonction : <s:property value="%{#session.employe.emploi.nomEmploi}"/>

但问题是它没有显示任何内容。

所以为你解释我有一个包含另一个类就业的员工类,这里是示例代码

雇工:

public class Employe 
{
  private Long employeId;
  private Emploi emploi;
  private String nom;
  private String prenom;
  private String adresse;
  private String civilite;

  @Id
  @GeneratedValue(strategy = IDENTITY)
  @Column(name = "ID", unique = true, nullable = false)
  public Long getEmployeId() {
    return this.employeId;
}

public void setEmployeId(Long employeId) {
    this.employeId = employeId;
}

    @ManyToOne(fetch = FetchType.LAZY)
@JoinColumn(name = "EMP_ID", nullable = false)
    public Emploi getEmploi() {
    return this.emploi;
}

public void setEmploi(Emploi emploi) {
    this.emploi = emploi;
}
    @Column(name = "NOM", nullable = false)
    public String getNom() {
    return this.nom;
}

public void setNom(String nom) {
    this.nom = nom;
}
    @Column(name = "PRENOM", nullable = false)
    public String getPrenom() {
    return this.prenom;
}

public void setPrenom(String prenom) {
    this.prenom = prenom;
}

    @Column(name = "ADRESSE", nullable = false)
    public String getAdresse() {
    return this.adresse;
}

public void setAdresse(String adresse) {
    this.adresse = adresse;
}
    @Column(name = "CIVILITE", nullable = false, length = 20) 
    public String getCivilite() {
    return this.civilite;
}

public void setCivilite(String civilite) {
    this.civilite = civilite;
}
}

EMPLOI:

public class Emploi
{
  private Long emploiId;
  private String nomEmploi;
  private Set<Employe> employes = new HashSet<Employe>(0);
  @Id
  @GeneratedValue(strategy = IDENTITY)
  @Column(name = "EMP_ID", unique = true, nullable = false)
  public Long getEmploiId() {
    return this.emploiId;
}

public void setEmploiId(Long emploiId) {
    this.emploiId = emploiId;
}
    @Column(name = "NOM_EMPLOI", nullable = false)
public String getNomEmploi() {
    return this.nomEmploi;
}

public void setNomEmploi(String nomEmploi) {
    this.nomEmploi = nomEmploi;
}
    @OneToMany(fetch = FetchType.LAZY, mappedBy = "emploi")
    public Set<Employe> getEmployes() {
    return this.employes;
}

public void setEmployes(Set<Employe> employes) {
    this.employes = employes;
}

}

任何帮助将不胜感激。

提前致谢。

1 个答案:

答案 0 :(得分:1)

确保会话中的对象是可用的;

使用下面的标记,您将了解ValueStack中可用的对象。

<s:debug/>

输出值堆栈的内容。

另一种方法是将项目放在devMode下面,在struts.xml中添加常量。

<constant name="struts.devMode" value="true" />
  

http://localhost:8080/yourApplication/yourActionName.action?debug=xml