package com.liuxiaoyu.crm.action;import java.util.List;
import com.liuxiaoyu.crm.model.Employee;
import com.liuxiaoyu.crm.service.EmployeeManager;
import com.opensymphony.xwork2.ActionSupport;public class EmployeeAction extends ActionSupport { private EmployeeManager employeeManager;
private Employee employee;
private Long id; public List employeelist;
    
public List getEmployeelist() {
return employeelist;
}
public void setEmployeelist(List employeelist) {
this.employeelist = employeelist;
} public String list_Emp ()
{
this.employeelist=employeeManager.getEmps();
System.out.print(employeelist.size());
for(int i=0;i<employeelist.size();i++)
{
employee=(Employee) employeelist.get(i);
System.out.println("ID:"+employee.getId().toString());
System.out.println("Name"+employee.getName().toString());
System.out.println("Address:"+employee.getAddress().toString());
System.out.println("Phone:"+employee.getPhone().toString());
}
return SUCCESS;
} public Long getId() {
return id;
} public void setId(Long id) {
this.id = id;
} public Employee getEmployee() {
return employee;
} public void setEmployee(Employee employee) {
this.employee = employee;
} public void setEmployeeManager(EmployeeManager employeeManager) {
this.employeeManager = employeeManager;
} public String add_Emp()
{
this.employeeManager.addEmp(employee);
return SUCCESS;
} public String delete_Emp()
{
employeeManager.deleteEmp(id);
return SUCCESS;
}



public String get_EmployeeOne()
{
employee=employeeManager.getEmp(id);
return SUCCESS;
}

}
==========================================
<%@ page language="java" import="java.util.*" pageEncoding="utf-8"%>
<%@ taglib uri="/struts-tags" prefix="s"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN">
<html>
<head> <title>List page</title> <meta http-equiv="pragma" content="no-cache">
<meta http-equiv="cache-control" content="no-cache">
<meta http-equiv="expires" content="0">
<meta http-equiv="keywords" content="keyword1,keyword2,keyword3">
<meta http-equiv="description" content="This is my page">
<!--
<link rel="stylesheet" type="text/css" href="styles.css">
-->
</head>
<body>
<table>
<s:iterator value="employeelist">
<s:property value="Id" />
 <s:property value="Name" />
 <s:property value="address" />
<s:property value="phone" />
</s:iterator>
</table>
</body>
</html>
后台我看了list里是有东西的.可是就是在前边取不到....action中加了get  set 方法了,,不知道是那的错,请高人指点.
(Oracle中有数据,并且以调了list_Emp方法,可以输出employee的值 )

解决方案 »

  1.   

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts PUBLIC
                    "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"
                    "http://struts.apache.org/dtds/struts-2.0.dtd" >
    <struts>
    <!-- 添加常量   把struts 交spring管理  -->
    <constant name="struts.objectFactory" value="spring" />
    <!--
    from 中提交 的ACTION名子是add 就会在这找名为name=add的 再通过spring中addBean所对应的类,
    再在类中调用名为method="add" 的方法
    -->
    <package name="crm_employee"  extends="struts-default" >
    <action name="add" class="addBean" method="add_Emp">
    <result type= "redirect-action" >list.action</result>
    </action>

    <action name="list" class="listBean" method="list_Emp">
        <result type="redirect">list.jsp</result>
    </action>

    <action name="list.action" class="listBean" method="list_Emp">
        <result type="redirect">list.jsp</result>
    </action>
    </package>


    </struts>
      

  2.   


    public String list_Emp () 

    List employeelist=employeeManager.getEmps(); 
    System.out.print(employeelist.size()); 
    ActionContext.getContext().put("employeelist", employeelist);
    return SUCCESS; 

      

  3.   

    <action name="list" class="listBean" method="list_Emp">
        <result type="redirect">list.jsp </result>
    </action><action name="list.action" class="listBean" method="list_Emp">
        <result type="redirect">list.jsp </result>
    </action> 你的action里面配置的type都是redirect重定向了 自然action里面的值就丢失了
    要么你这里不要用重定向 要么你把值放在session里