1

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

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

但它不显示任何内容的问题。

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

雇员:

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;
}
}

雇用:

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;
}

}

任何帮助将不胜感激。

提前致谢。

4

1 回答 1

1

确保该对象在会话中可用;

使用下面的标签,您将了解 ValueStack 中可用的对象是什么。

<s:debug/>

输出值栈的内容。

另一种方法是让您的项目devMode在 struts.xml 中添加下面的常量。

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

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

于 2012-11-21T04:14:11.920 回答