Action返回自定义类的List集合通过JSP中的Struct2标签显示

Action返回自定义类的List集合通过JSP中的Struct2标签显示

有时候,通过数据库查询出来的数据需要显示在页面上,但是Action中返回的只有List<Object>易于操作,所以需要在Jsp页面调用标签显示


不多说,上代码


package org.action;

import java.util.ArrayList;
import java.util.List;

import org.dao.ShowDao;
import org.vo.Goods;

import com.opensymphony.xwork2.ActionSupport;

public class ShowAction extends ActionSupport{
	List<Goods> goods = new ArrayList<Goods>();

	public List<Goods> getGoods() {
		return goods;
	}

	public void setGoods(List<Goods> goods) {
		this.goods = goods;
	}
	public String execute(){
		
		Goods good = new Goods();
		Goods good1 = new Goods();
		Goods good2 = new Goods();
		Goods good3 = new Goods();
		
		goods.add(good);
		goods.add(good1);
		goods.add(good2);
		goods.add(good3);
		
		
		return SUCCESS;
	}
	
	

}


java代码返回的是List<Object>对象然后需要显示在jsp页面


上代码


<table class="bordered">
<caption><h1>商品列表</h1></caption>
    <thead>

    <tr>
        <th>#</th>        
        <th>名称</th>
        <th>地址</th>
        <th>简介</th>
        <th>当前价格</th>
        <th>原价</th>
    </tr>
    </thead>
    <s:iterator value="goods" status="st" id="good">
    
    
    
    <tr>
    
    	<td><s:property value="#good.getId()"/></td>
    	<td><s:property value="#good.getName()"/></td>
    	<td><s:property value="#good.getPath()"/></td>
    	<td><s:property value="#good.getIntro()"/></td>
    	<td><s:property value="#good.getCost_price()"/></td>
    	<td><s:property value="#good.getPresent_price()"/></td>
    
    </tr>
  
  
  
  
  
    </s:iterator>
    
    

</table>





此上所用的


<s:iterator value="goods" status="st" id="good">
	<s:property value="#good.getName()"/>
</s:iterator>

只可以说出到页面上

如果你想这样输出Action中的数据,


<s:textfield name="good.name" label="名称" value="<s:property value="#good.getName()"/>"/>

抱歉不可以的


<s:textfield name="good.name" label="名称" value="%{#good.getName()}"/>

换成OGNL就可以了具体 为什么这样写我就不知道了







评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值