hello.no.username.error  
是对应文件
ApplicationResources_ch.properties
中的一项的。这个文件在strus-config.xml中配置的
  <!-- ========== Message Resources Definitions =========================== -->  <message-resources    parameter="ApplicationResources_ch.properties"/>  <message-resources    parameter="AlternateApplicationResources"
                         key="alternate">
  </message-resources>

解决方案 »

  1.   

    这里的username与什么有关??
    errors.add("username",new ActionMessage("hello.no.username.error"));
    resouce文件
    hello.baduser.monster=you cannot talk with Monster!!!
    hello.no.username.error=please intput user name.
    hello.hello=show hello
    jsp
    <logic:present name="personbean" scope="request">
    <bean:write name="personbean" property="userName" />
    </logic:present>
    <html:form action="/hello" focus="userName">
    <html:text property="userName"/>
    <br>
    <html:submit property="submit" value="submit" />
    <html:reset />
    </html:form>
    </body>
      

  2.   

    errors.add(ActionErrors.GLOBAL_ERROR,new ActionMessage("hello.no.username.error"));
    这里的hello.no.username.error只是做为从ApplicationResources_ch.properties文件取值的标志,
    只要能对应就行了。
      

  3.   

    jsp文件
    <%@ page language="java"%>
    <%@ taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%> 
    <%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@ taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
    <html:html locale="true">
    <head>
    <title>JSP for helloForm form</title>
    <html:base/>
    </head>
    <body>
    <html:errors/><p>
    <logic:present name="personbean" scope="request">
    <bean:write name="personbean" property="userName" />
    </logic:present>
    <html:form action="/hello" focus="userName">
    <html:text property="userName"/>
    <br>
    <html:submit property="submit" value="submit" />
    <html:reset />
    </html:form>
    </body>
    </html:html>
      

  4.   

    resource文件
    # Resources for parameter 'com.yourcompany.struts.ApplicationResources'
    # Project P/helloWeb
    hello.baduser.monster=you cannot talk with Monster!!!
    hello.no.username.error=please intput user name.
    hello.hello=show hello
      

  5.   

    form文件
    package com.yourcompany.struts.form;import javax.servlet.http.HttpServletRequest;import org.apache.struts.action.ActionErrors;
    import org.apache.struts.action.ActionForm;
    import org.apache.struts.action.ActionMapping;
    import org.apache.struts.action.ActionMessage;
    /** 
     * MyEclipse Struts
     * Creation date: 10-12-2004
     * 
     * XDoclet definition:
     * @struts:form name="helloForm"
     */
    public class HelloForm extends ActionForm { // --------------------------------------------------------- Instance Variables // --------------------------------------------------------- Methods    private String userName = null;    public String getUserName() {
            return (this.userName);
        }    public void setUserName(String userName) {
            this.userName = userName;
        }
       
        /**
         * Reset all properties to their default values.
         */
        public void reset(ActionMapping mapping, HttpServletRequest request) {
            this.userName = null;
        }    /**
         * Validate the properties posted in this request. If validation errors are
         * found, return an <code>ActionErrors</code> object containing the errors.
         * If no validation errors occur, return <code>null</code> or an empty
         * <code>ActionErrors</code> object.
         */
        public ActionErrors validate(ActionMapping mapping,
                                     HttpServletRequest request) {        ActionErrors errors = new ActionErrors();        if ((userName == null) || (userName.length() < 1))
                errors.add("username", new ActionMessage("hello.no.username.error"));        return errors;
        }
    }
      

  6.   

    public ActionErrors validate(ActionMapping mapping,
                                     HttpServletRequest request) {        ActionErrors errors = new ActionErrors();        if ((userName == null) || (userName.length() < 1))
                errors.add("username", new ActionMessage("hello.no.username.error"));        return errors;
        }
    改成     public ActionErrors validate(ActionMapping mapping,
                                     HttpServletRequest request) {        ActionErrors errors = new ActionErrors();        if ((userName == null) || (userName.length() < 1))
                errors.add("username", new ActionError("hello.no.username.error"));        return errors;
        }
      

  7.   

    xunyiren(从jsp开始) ( ) 
    改了也不行。
    errors.add("username",new ActionMessage("hello.no.username.error"));
    这里的username是什么地方设置的??我看了别人的成功代码,仿作到这里出问题,
    STRUTS架构和ressouce文件使用都没问题,struts1.1
      

  8.   

    那你Action里的代码还用原来的,把页上的<html:errors/>换成<html:messages id="message" property="username">
       <bean:write name="message"/>
    </html:messages>
      

  9.   

    errors.add("org.apache.struts.action.GLOBAL_ERROR", new ActionError("hello.no.username.error"));改成如上代码,一切ok,但说真的,这个问题没有搞得很清楚原代码
    <html:form action="/hello" focus="userName">
    <html:text property="userName"/>
    <html:submit property="submit" value="submit" />
    <html:reset />和errors.add("userName",new ActionMessage("hello.no.username.error"));,其中username还是userName效果都一样,不行.
    老大帮忙分析一下原因.我做了也头晕,不知道其所以然.而且,其他人的成功代码用username也通过的!!
      

  10.   

    假如要使用username,那么对应的"锚点"username,在什么地方进行设置!!
      

  11.   

    你的配置信息要在web.xml中加啊!!!!!
      

  12.   

    假如要使用username,那么对应的"锚点"username,在什么地方进行设置!!这个不需要什么设置!errors.add("username", new ActionError("hello.no.username.error"));
    这个相当于用一个名为"username"的键去映射当用户名为空时的出错信息,这样在页面上显示出错信息时我们就可以指定自己要显示的对应字段的出错信息,而且位置比较灵活,如你有多个表单域
    html:text property="userName"/><html:errors property="username"/>
    html:text property="userId"/><html:errors property="userid"/>
    这样如果出错,出错信息显示在相应的字段旁边...
    而如果你想显示在 ActionErrors中保存的所有出错信息时,则只需<html:errors/>这一句。