create table p_kind
(
id int primary key identity(1,1),
name varchar2(20)
)create table product
(
id int primary key identity(1,1),
name varchar2(20),
price float,
stocks  int,
discription varchar(1024),
p_kind_id int references p_kind(id) //主外键
) <s:property value="#p.PKind.name"/> [color=#FF0000][color=#3366FF]//这里取p_kind姓名  </td[/color]>[/color]   但是这样写页面上显示的值是 空白 的。
 <body>
  <h3>产品展示</h3>
  <table align="center" border="2">
  <tr>
  
  <td>
  编号
  </td>
  
   <td>
  产品名称
  </td>
  
   <td>
  价格
  </td>
  
   <td>
  库存
  </td>
  
  
   <td>
  产品描述
  </td>
  
  <td>
  产品类别
  </td>
  
  </tr>
  
  
  <s:iterator id="p" value="#request.list">
  <tr>
  <td>
  <s:property value="#p.id "/>
  </td>
  
   <td>
  <s:property value="#p.name "/>
  </td>
  
   <td>
  <s:property value="#p.price "/>
  </td>
  
   <td>
  <s:property value="#p.stocks "/>
  </td>
  
   <td>
  <s:property value="#p.discription "/>
  </td>
  
   <td>
  <s:property value="#p.PKind.name"/> [color=#3366FF]//这里取p_kind姓名  </td[/color]>
  
   <td>
 <s:a href="" cssStyle="color:red" >加入购物车</s:a>
  </td>
  
  </tr>
  
  
  </s:iterator>
  
  </table>
  </body>
</html>

解决方案 »

  1.   

    p.PKind.name好像不是这样的吧,p.PKindId.PKind.name这样呢?
      

  2.   

    检查下查询完PKind对象里面有值不
      

  3.   


    private Integer id;
    private String name;
    private String discription;
    private Set products = new HashSet(0); // Constructors /** default constructor */
    public PKind() {
    } /** full constructor */
    public PKind(String name, String discription, Set products) {
    this.name = name;
    this.discription = discription;
    this.products = products;
    } // Property accessors public Integer getId() {
    return this.id;
    } public void setId(Integer id) {
    this.id = id;
    } public String getName() {
    return this.name;
    } public void setName(String name) {
    this.name = name;
    } public String getDiscription() {
    return this.discription;
    } public void setDiscription(String discription) {
    this.discription = discription;
    } public Set getProducts() {
    return this.products;
    } public void setProducts(Set products) {
    this.products = products;
    }
      

  4.   

    我是说你后台执行完查询
    打印下PKind的name
    看有不有
      

  5.   


    额 是没有name的值 报了java.lang.NullPointerException
    但是id的值有
      

  6.   


    sql语句我就用了dao中的findAll()方法
      

  7.   

     String hql="select p p.PKind.name from Product as p"; 正确答案