------jsp页面文件
///////index.jsp<%@ taglib uri="/WEB-INF/tlds/struts-html.tld" prefix="html" %><html>
<head>
<title>minihr index.jsp file</title>
</head><body>
<font size=3>AAA,Inc.Human Resources Portal------index.jsp page</font>
<br>
<hr width=100% noshade=true>&#149; Add an Employee<br>
&#149;<html:link forward="search">Search for Employees</html:link><br></body>
</html> //////////search.jsp
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld/" prefix="bean" %>
<%@ taglib uri="/WEB-INF/tlds/struts-html.tld/" prefix="html" %>
<%@ taglib uri="/WEB-INF/tlds/struts-logic.tld/" prefix="logic" %><html>
<head>
<title>minihr search.jsp file</title>
</head><body>
<font size=3>AAA,Inc.Human Resources Portal------search.jsp page</font>
<br>
<hr width=100% noshade=true><html:errors/><html:form action="/search">
<table width="722" height="214" border="1" cellpadding="2" cellspacing="4">
  <tr>
    <td width="303"><bean:message key="label.search.name"/>:</td>
    <td width="419"><html:text property="name"/></td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td>----or----</td>
  </tr>
  <tr>
    <td><bean:message key="label.search.ssNum"/>:</td>
    <td><html:text property="ssNum"/>(xxx-xx-xxxx)</td>
  </tr>
  <tr>
    <td>&nbsp;</td>
    <td><html:submit/></td>
  </tr>
</table>
</html:form><logic:present name="searchForm" property="results"> <hr width=100% noshade=true> <bean:size id="size" name="searchForm" property="results"/> <logic:equal name="size" value="0">
<center><font color=red><b>Inspite of you entered the name,but,No Employees Found</b></font></center>
</logic:equal> <logic:greaterThan name="size" value="0">
<table border=1>
<tr>
<td>name</td><td>Social Security Number</td>
</tr> <logic:iterate id="result" property="searchForm" property="results">
<tr>
<td><bean:write name="result" property="name"/></td>
<td><bean:write name="result" property="ssNum"/></td>
</tr>
</logic:iterate> </table>
</logic:greaterThan></logic:present>
</body>
</html>
------------------配置文件
//////////web.xml<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE web-app
  PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
  "http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">
<web-app>
  <display-name>Struts Examples Application</display-name>  <!-- Standard Action Servlet Configuration (with debugging) -->
  <servlet>
    <servlet-name>action</servlet-name>
    <servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
<init-param>
      <param-name>config</param-name>
      <param-value>/WEB-INF/struts-config.xml</param-value>
    </init-param>
    <init-param>
      <param-name>debug</param-name>
      <param-value>2</param-value>
    </init-param>
    <init-param>
      <param-name>detail</param-name>
      <param-value>2</param-value>
    </init-param>
    <load-on-startup>2</load-on-startup>
  </servlet>  <!-- Standard Action Servlet Mapping -->
  <servlet-mapping>
    <servlet-name>action</servlet-name>
    <url-pattern>*.do</url-pattern>
  </servlet-mapping>
  <!-- The Usual Welcome File List -->
  <welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
    <welcome-file>index.htm</welcome-file>
  </welcome-file-list>  <!--StrutsTag Library Descriptors-->
  <taglib>
<taglib-uri>/WEB-INF/tlds/struts-bean.tld</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-bean.tld</taglib-location>
  </taglib>  <taglib>
<taglib-uri>/WEB-INF/tlds/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-html.tld</taglib-location>
  </taglib>  <taglib>
<taglib-uri>/WEB-INF/tlds/struts-logic.tld</taglib-uri>
<taglib-location>/WEB-INF/tlds/struts-logic.tld</taglib-location>
  </taglib></web-app>
/////struts-config.xml<?xml version="1.0" encoding="iso-8859-1"?>
<!DOCTYPE struts-config PUBLIC
          "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN"
          "http://struts.apache.org/dtds/struts-config_1_2.dtd">
<!--
  Default configuration file for examples application.
  Each module also has its own struts-config under: /WEB-INF/$MODULE/
  @version $Revision: 1.9 $ $Date: 2004-09-06 19:50:06 -0700 (Mon, 06 Sep 2004) $
-->
<struts-config>
  <form-beans>
<form-bean name="searchForm" type="test.SearchForm"/>
  </form-beans>
 
  <global-forwards>
<forward name="search" path="/search.jsp" />
  </global-forwards>
 
  <action-mappings>
<action path="/search"
type="test.SearchAction"
name="searchForm"
scope="request"
validate="true"
input="/search.jsp">
</action>
  </action-mappings>  <!--Message Resources Configration-->
  <message-resources parameter="test.ApplicationResources"/></struts-config>
------------------ApplicationResources.properties
/////////ApplicationResources.properties
# Label Resources
label.search.name=姓名
label.search.ssNum=社会保险号码#Error Resources
error.search.criteria.missing=<li>Search Criteria Missing 查找标准错误</li>
error.search.ssNum.invalid=<li>Invalid Social Security Number 无效的社会保险号码</li>
errors.header=<font color="red"><b>Validation Error(s) 无效错误</b></font><ul>
errors.footer=</ul><hr width="100$" size="1" noshade="true">

解决方案 »

  1.   

    异常不是告诉你了嘛 Null attribute name
      

  2.   

    是不是你在request.getAttribute或者session.getAttribute的时候要取得的属性名称没有写对或者事先没有设置这个名字的属性
      

  3.   

    set 的名字与 get 时的不同建义写个类里面全是public static final String name="---";这样可以避免这个异常再次出现
      

  4.   

    我觉得是这段代码的问题:
    <logic:iterate id="result" property="searchForm" property="results">
    <tr>
    <td><bean:write name="result" property="name"/></td>
    <td><bean:write name="result" property="ssNum"/></td>
    </tr>
    </logic:iterate>result是results的一个元素,怎么会有name,ssNum属性?
      

  5.   

    仔细检查了 laughsmile(海边的星空) 所说的代码,发现还真有问题 <logic:iterate id="result" property="searchForm" property="results"> 应该是<logic:iterate id="result" name="searchForm" property="results"> 原来是写错了一个单词,差点晕倒,很感激大家 的帮助,结贴!