目的是用 ApplicationResources.properties 定义的信息 在JSP下显示错误信息
是一个登录界面
用strurs做的
首相想问下ApplicationResources.properties  是不是放在WEB-INF 文件夹下的
我用的是Eclipse
下面是部分代码

解决方案 »

  1.   

    Action文件
    public ActionForward execute(ActionMapping arg0, ActionForm arg1,
    HttpServletRequest arg2, HttpServletResponse arg3) throws Exception {
    // TODO Auto-generated method stub
    ActionFrm userinfo = (ActionFrm) arg1;
    DAO dao = new DAO();
    ActionFrm af = dao.checkLogin(userinfo.getUserid());
    boolean flag = true;
    ActionErrors errors =new ActionErrors();

    String p = "password error";
    String u = "userid error";
    if(af!=null)
    {
    if(af.getPsw().equals(userinfo.getPsw()))
    flag=true;
    else
    {
    flag=false;
    errors.add("psw",new ActionMessage("error.password.required","pp"));
    this.saveErrors(arg2,errors);
    }

    }
    else
    {
    flag=false;
    errors.add("name",new ActionMessage("error.username.required","uu"));
    this.saveErrors(arg2,errors);

    }


    if(flag)
    return arg0.findForward("loginOK");
    else
    {
    return arg0.findForward("loginFail");
    }


    }
      

  2.   

    JSP代码
    <%@page contentType="text/html; charset=GBK"%>
    <%@taglib uri="/WEB-INF/struts-html.tld" prefix="html"%>
    <%@taglib uri="/WEB-INF/struts-logic.tld" prefix="logic"%>
    <%@taglib uri="/WEB-INF/struts-bean.tld" prefix="bean"%>
    <html>
    <head>
    <title>login</title>
    </head>
    <body>
    <center>login</center>
    <html:form action="actuser">
    <table>
       <tr>
          <td>userid:</td>
          <td><html:text property="userid"/></td>
       </tr>
       <font color=red> <html:errors property="name"/></font><br></br>
       <tr>
          <td>password:</td>
          <td><html:password property="psw"/></td>
       </t>    
       <font color=red> <html:errors property="psw"/></font><br></br>
          <td></td>
          <td><input type="submit" value="登录"></td>
       </tr>
    </table>

    </html:form>
    </body>
    </html>
      

  3.   

    ApplicationResources.properties 放在src下就可以了。你在struts-config.xml文件里配置一下:
    <message-resources [color=#993366]parameter="com.struts.ApplicationResources" />[/color]parameter的值就按照ApplicationResources.properties的包路径的形式写就可以了。
      

  4.   

    <?xml version="1.0" encoding="UTF-8"?>
    <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.1//EN" "http://jakarta.apache.org/struts/dtds/struts-config_1_1.dtd">
    <struts-config>
      <form-beans>
        <form-bean name="actionfrm" type="cn.edu.zucc.text.ActionFrm"/>
        </form-beans>
      <global-forwards>
        <forward contextRelative="true" name="loginOK" path="/main.jsp"/>
        <forward contextRelative="true" name="loginFail" path="/index.jsp"/>    
      </global-forwards>
      <action-mappings>
        <action input="/index.jsp" validate="true" name="actionfrm" parameter="method" path="/actuser" scope="request" type="cn.edu.zucc.text.ActUser">
          
        </action>
      </action-mappings>
      <message-resources parameter="cn.edu.zucc.text.ApplicationResources"/>
    </struts-config>
      

  5.   

    这是 struts-config文件
    还是不行
      

  6.   

    HTTP Status 500 - --------------------------------------------------------------------------------type Exception reportmessage description The server encountered an internal error () that prevented it from fulfilling this request.exception org.apache.jasper.JasperException: org.apache.struts.action.ActionMessage
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:372)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
    org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    root cause java.lang.ClassCastException: org.apache.struts.action.ActionMessage
    org.apache.struts.taglib.html.ErrorsTag.doStartTag(ErrorsTag.java:215)
    org.apache.jsp.index_jsp._jspx_meth_html_errors_0(index_jsp.java:176)
    org.apache.jsp.index_jsp._jspx_meth_html_form_0(index_jsp.java:120)
    org.apache.jsp.index_jsp._jspService(index_jsp.java:79)
    org.apache.jasper.runtime.HttpJspBase.service(HttpJspBase.java:94)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    org.apache.jasper.servlet.JspServletWrapper.service(JspServletWrapper.java:324)
    org.apache.jasper.servlet.JspServlet.serviceJspFile(JspServlet.java:292)
    org.apache.jasper.servlet.JspServlet.service(JspServlet.java:236)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    org.apache.struts.action.RequestProcessor.doForward(RequestProcessor.java:1069)
    org.apache.struts.action.RequestProcessor.processForwardConfig(RequestProcessor.java:455)
    org.apache.struts.action.RequestProcessor.process(RequestProcessor.java:279)
    org.apache.struts.action.ActionServlet.process(ActionServlet.java:1482)
    org.apache.struts.action.ActionServlet.doPost(ActionServlet.java:525)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:763)
    javax.servlet.http.HttpServlet.service(HttpServlet.java:856)
    note The full stack trace of the root cause is available in the Apache Tomcat/5.0.26 logs.
      

  7.   

    就是这样的,放在src下就可以 ,再在struts-config.xml里注册下就可以了
      

  8.   

    在Action里应该这么写:
    ActionMessages errors = new ActionMessages();//注意是ActionMessages而不是ActionErrors
    errors.add("",new ActionMessage("xxx"));
    this.saveErrors(request,errors);
    ....
      

  9.   

    this.saveErrors(request,errors);  会报错的
    参数不符合