white-page.jsp<%@page pageEncoding="UTF-8"%>
<%@page isELIgnored="false"%>
<%@ taglib uri="/WEB-INF/tlds/struts-bean.tld" prefix="bean" %>
<bean:message key="sso.onlinetest.result"/>想要得到sso.onlinetest.result
但总是拿到null
if((name.length() < 4) || (name.length() > 20)){
            message = new ActionMessage("sso.onlinetest.result", "错误:用户名必须在4-20位长度之间!");
        } ...
        messages.add(ActionMessages.GLOBAL_MESSAGE, message);
        return messages;若用户名小于4个单词
我就将错误写在sso.onlinetest.result键里
以下是资源包sso.label.username=Username:
sso.label.password=Password:
...sso.onlinetest.result={0}
最后是外层的action
public ActionForward execute(ActionMapping mapping,
            ActionForm form,
            HttpServletRequest request,
            HttpServletResponse response) throws Exception {
        
        String username = request.getParameter("username");
        String nickname = request.getParameter("nickname");
                   
        response.setHeader("Charset","utf-8");         ActionMessages messages = null;
        if(username != null){
            username = new String(username.getBytes("ISO8859-1"),"UTF-8");
            
            OnlineTestService testService = new UsernameOnlineTestService(username);
            messages = testService.test();
        }
        else if(nickname != null){
            nickname = new String(nickname.getBytes("ISO8859-1"),"UTF-8");
            
            OnlineTestService testService = new UsernameOnlineTestService(username);
            messages = testService.test();
        }
        
        this.saveMessages(request, messages);
                
        return mapping.findForward("white-page");
    }不知道哪里有错!请高手指点!

解决方案 »

  1.   

    这样的错误消息不能用bean:message标记输出,应该用<html:messages id="messages" message="true">
          <bean:write name="messages" />
        </html:messages>
      

  2.   

    <bean:message>标记是用来输出资源(ApplicationResource.properties)文件里的内容的,key是资源文件的中键。你的资源文件如果没有用这个键的消息的话,当然是null了。
      

  3.   

    #
    #   Copyright (c) 2004-2006, Novascope S.A. and the JOSSO team
    #    All rights reserved.
    #    Redistribution and use in source and binary forms, with or
    #    without modification, are permitted provided that the following
    #    conditions are met:
    #
    #    * Redistributions of source code must retain the above copyright
    #      notice, this list of conditions and the following disclaimer.
    #
    #    * Redistributions in binary form must reproduce the above copyright
    #      notice, this list of conditions and the following disclaimer in
    #      the documentation and/or other materials provided with the
    #      distribution.
    #
    #    * Neither the name of the JOSSO team nor the names of its
    #      contributors may be used to endorse or promote products derived
    #      from this software without specific prior written permission.
    #
    #    THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND
    #    CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES,
    #    INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
    #    MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE
    #    DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT OWNER OR CONTRIBUTORS
    #    BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
    #    EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED
    #    TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE,
    #    DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
    #    ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY,
    #    OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
    #    OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE
    #    POSSIBILITY OF SUCH DAMAGE.
    ## -- standard errors --
    #errors.suffix=</li>
    #errors.prefix=<li>
    #errors.header=<ul class="error-msg"><font color="red" face="Verdana">
    #errors.footer=</font></ul># -- SSO Message Resources
    sso.label.username=Username:
    sso.label.password=Password:
    sso.info.session={0}sso.button.login=Loginsso.login.success={0}!
    sso.login.redirect=You'll be redirected to your <a href="{0}">site</a>
    sso.login.failed=Invalid Authentication Informationsso.error=Error : {0}
    sso.onlinetest.result={0}我的ApplicationResource.properties,不是有sso.onlinetest.result={0}这一行吗?
    sso.onlinetest.result不是键吗?
    谢谢老大再解答一下哦
      

  4.   

    sso.onlinetest.result={0}是需要通过程序动态赋值的,但你在程序中并没有给这个键的消息赋值,而是用的ActionMessages.GLOBAL_MESSAGE作为消息的键,如果你改成sso.onlinetest.result=asdfas{0}这样的话用bean:message就会输出asdfas了,如果你想在程序中动态赋值,就这样写messages.add("sso.onlinetest.result", "value1");
    用<html:message>就会输出asdfasvalue1了。