学习struts2的时候用到valueStack传递数据库数据到jsp页面。
action类中, 实体集合对象作为属性,
拦截action的时候exectue方法给属性实例化
jsp用<s:iterator value="customers">迭代取出来的时候,
customers集合对象就只存在了4个属性,其他的貌似没放进去,
但是在exectue方法中测试实体集合的中每个对象的每个属性都是存在的,这是啥情况。
package action;
import java.util.*;import orm.Customer;import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;import dao.CustomerDao;
import dao.impl.CustomerDaoImpl;public class SelectCustomers extends ActionSupport { private List<Customer> customers=null;
public List<Customer> getCustomers() {
return customers;
}
public void setCustomers(List<Customer> customers) {
this.customers = customers;
}
public String execute() throws Exception {
CustomerDao cDao=new CustomerDaoImpl();
customers=cDao.selCustomer(null);//为了测试集合对象的完整,遍历了此集合输出到控制台
for (Customer customer : customers) {
System.out.print(customer.getCid());
System.out.print(customer.getCname());
System.out.print(customer.getLiveness());
System.out.print(customer.getOfficePhone());
System.out.print(customer.getcStatus());
System.out.print(customer.getcType());
System.out.print(customer.getcSource());
System.out.println(customer.getcDate());
}
return "show";
}
}
struts2的action类配套的xml配置<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="action" namespace="/*" extends="struts-default">
<action name="listCustomerAction" class="action.SelectCustomers">
<result name="show">/MyJsp.jsp</result>
</action>
</package>
</struts>
jsp页面,已导入struts2标签库。<s:iterator value="customers">
<tr>
<td height="20">
<s:property value="cid" />
</td>
<td>
<s:property value="cname" />
</td>
<td>
<s:property value="liveness" />
</td>
<td>
<s:property value="OfficePhone" />
</td>
<td>
<!-- 就这里开始,没数据了-->
<s:property value="cStatus" />
</td>
<td>
<s:property value="cType" />
</td>
<td>
<s:property value="cSource" />
</td>
<td>
<s:property value="cDate" />
</td>
<br />
</tr>
</s:iterator>
部分debug内容,就只有4个属性Struts ValueStack DebugValue Stack Contents
Object Property Name Property Value
action.SelectCustomers texts null
actionErrors []
errors {}
fieldErrors {}
errorMessages []
container There is no read method for container
locale zh_CN
actionMessages []
//只有4个属性放进去了
customers [orm.Customer@4848268a, orm.Customer@78da5318, orm.Customer@45858aa4, orm.Customer@425138a4]
com.opensymphony.xwork2.DefaultTextProvider texts null
action类中, 实体集合对象作为属性,
拦截action的时候exectue方法给属性实例化
jsp用<s:iterator value="customers">迭代取出来的时候,
customers集合对象就只存在了4个属性,其他的貌似没放进去,
但是在exectue方法中测试实体集合的中每个对象的每个属性都是存在的,这是啥情况。
package action;
import java.util.*;import orm.Customer;import com.opensymphony.xwork2.Action;
import com.opensymphony.xwork2.ActionSupport;import dao.CustomerDao;
import dao.impl.CustomerDaoImpl;public class SelectCustomers extends ActionSupport { private List<Customer> customers=null;
public List<Customer> getCustomers() {
return customers;
}
public void setCustomers(List<Customer> customers) {
this.customers = customers;
}
public String execute() throws Exception {
CustomerDao cDao=new CustomerDaoImpl();
customers=cDao.selCustomer(null);//为了测试集合对象的完整,遍历了此集合输出到控制台
for (Customer customer : customers) {
System.out.print(customer.getCid());
System.out.print(customer.getCname());
System.out.print(customer.getLiveness());
System.out.print(customer.getOfficePhone());
System.out.print(customer.getcStatus());
System.out.print(customer.getcType());
System.out.print(customer.getcSource());
System.out.println(customer.getcDate());
}
return "show";
}
}
struts2的action类配套的xml配置<?xml version="1.0" encoding="UTF-8" ?>
<!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.1//EN" "http://struts.apache.org/dtds/struts-2.1.dtd">
<struts>
<package name="action" namespace="/*" extends="struts-default">
<action name="listCustomerAction" class="action.SelectCustomers">
<result name="show">/MyJsp.jsp</result>
</action>
</package>
</struts>
jsp页面,已导入struts2标签库。<s:iterator value="customers">
<tr>
<td height="20">
<s:property value="cid" />
</td>
<td>
<s:property value="cname" />
</td>
<td>
<s:property value="liveness" />
</td>
<td>
<s:property value="OfficePhone" />
</td>
<td>
<!-- 就这里开始,没数据了-->
<s:property value="cStatus" />
</td>
<td>
<s:property value="cType" />
</td>
<td>
<s:property value="cSource" />
</td>
<td>
<s:property value="cDate" />
</td>
<br />
</tr>
</s:iterator>
部分debug内容,就只有4个属性Struts ValueStack DebugValue Stack Contents
Object Property Name Property Value
action.SelectCustomers texts null
actionErrors []
errors {}
fieldErrors {}
errorMessages []
container There is no read method for container
locale zh_CN
actionMessages []
//只有4个属性放进去了
customers [orm.Customer@4848268a, orm.Customer@78da5318, orm.Customer@45858aa4, orm.Customer@425138a4]
com.opensymphony.xwork2.DefaultTextProvider texts null
解决方案 »
- 帮我看看这那里写错了,运行起来死活没反应
- jsp中包含的jspa文件是什么?
- 下拉框显示数据库的值
- 请问eclipse切换编辑窗口的快捷键是什么?
- 请问淘宝的面试流程,外地的报销车费吗,谁有淘宝java面试题?
- 错误分析:There is no Action mapped for namespace / and action name test3
- jsp 如何获取天气,股票,航班 等信息??
- 如果把这一段代码改成是从数据库里谈数据的呢?---------在线等待
- 急聘JAVA工程师
- 请教是不是一个应用必须要使用数据库连接池
- tomcat 6 Context 下面(Value className="org.apache.catalina.values.Remo) Value 配置问题
- 数据只保存一天?
<tr>
<td height="20">
<s:property value="#c.cid" />
</td>
<td>
<s:property value="#ccname" />
</td>
<td>
<s:property value="#cliveness" />
</td>
<td>
<s:property value="#c.OfficePhone" />
</td>
<td>
<!-- 就这里开始,没数据了-->
<s:property value="#c.cStatus" />
</td>
<td>
<s:property value="#c.cType" />
</td>
<td>
<s:property value="#c.cSource" />
</td>
<td>
<s:property value="#c.cDate" />
</td>
<br />
</tr>
</s:iterator>