你Struts几呢?用下面的方法试一下,我是Struts1.2用的是下面的方法。。
ActionMessages errors = new ActionMessages();
if((username == null)||(username.length()<1)){
errors.add("username",new ActionError("error.username.required"));
}

解决方案 »

  1.   

    唉,娃啊和我当时一样,把你的web.xml,和struts-config.xml贴出来!还有你的application.resources文件贴出来!
      

  2.   

    要么就是web.xml出问题了。要么就是res文件出问题了。
      

  3.   

    error.username.required 有设置吗?
      

  4.   

    请问楼主下面的代码
    ActionErrors errors=new ActionErrors();
    if((username == null)||(username.length()<1)){
    errors.add("username",new ActionError("error.username.required"));
    }
    是写在哪里的?
    如果是写在Form类的public ActionErrors validate(ActionMapping mapping,
    HttpServletRequest request)方法中,返回
    errors就应该可以显示出来;
    如果是在Action的execut方法中,那么还有调用saveErrors(request, errors);方法才可以。
      

  5.   

    上面的代码是在 ActionForm中,下面贴出相关代码
    web.xml:
    *********************************<?xml version="1.0" encoding="UTF-8"?>
    <web-app xmlns="http://java.sun.com/xml/ns/j2ee" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xsi:schemaLocation="http://java.sun.com/xml/ns/j2ee http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd" version="2.4">
      <jsp-config>
        <taglib>
          <taglib-uri>/WEB-INF/struts-bean.tld</taglib-uri>
          <taglib-location>/WEB-INF/struts-bean.tld</taglib-location>
        </taglib>
        <taglib>
          <taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
          <taglib-location>/WEB-INF/struts-html.tld</taglib-location>
        </taglib>
        <taglib>
          <taglib-uri>/WEB-INF/struts-logic.tld</taglib-uri>
          <taglib-location>/WEB-INF/struts-logic.tld</taglib-location>
        </taglib>
        <taglib>
          <taglib-uri>/WEB-INF/struts-template.tld</taglib-uri>
          <taglib-location>/WEB-INF/struts-template.tld</taglib-location>
        </taglib>
      </jsp-config>
      <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>application</param-name>
          <param-value>ApplicationResources</param-value>
        </init-param>
        <load-on-startup>2</load-on-startup>
      </servlet>
      <servlet-mapping>
        <servlet-name>action</servlet-name>
        <url-pattern>*.do</url-pattern>
      </servlet-mapping>
    </web-app>
    struts-config.xml:
    ************************************<?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.0//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_0.dtd">
    <struts-config>
      <form-beans>
        <form-bean name="logonForm" type="strutsapp.LogonForm" />
      </form-beans>  <global-forwards>
        <forward name="logon" path="/Logon.do"></forward>
        <forward name="logoff" path="/Logoff.do"></forward>
        <forward name="welcome" path="/Welcome.do"></forward>
      </global-forwards>  <action-mappings>
        <action path="/Welcome" type="org.apache.struts.actions.ForwardAction" parameter="/Welcome.jsp"/>
        <action path="/Logon" type="org.apache.struts.actions.ForwardAction" parameter="/Logon.jsp"/>
        <action path="/LogonSubmit" type="strutsapp.LogonAction" name="logonForm" scope="request" validate="false"  input="/Logon.jsp">
          <forward name="success" path="/Welcome.jsp"/>
        </action>
        <action path="/Logoff" type="strutsapp.LogoffAction">
          <forward name="success" path="/Welcome.jsp"/>
        </action>
      </action-mappings>
    </struts-config>
      

  6.   

    你配置错了,这样,比方说你的资源文件放在classes下面的resources文件夹中,资源文件为application.resources.
    你在web.xml中应该这样配置
    <init-param>
          <param-name>application</param-name>
          <param-value>resources.application</param-value>
        </init-param>
    还有在struts-config.xml中你还要配置一下,但是你没有配置!
      <message-resources  parameter="resources.application"/> 把这个代码放在
    </action-mappings>和</struts-config>之中,也就是倒数第二行!
    这样就好了!
    最好你把资源文件也贴出来