zhyiwww
用平实的笔,记录编程路上的点点滴滴………
posts - 536,comments - 394,trackbacks - 0
这个涉及到struts 1中的ActionMessages使用方法。

在action中
代码如下:

        ActionMessages messages = new ActionMessages();
        request.setAttribute(DefaultValue.REQUEST_NOTICE_MESSAGE, messages);

            messages.add("user.username", new ActionMessage(
                    "user already exist", false));

            messages.add("user.email", new ActionMessage("email already exist",
                    false));

在JSP页面中,代码如下:

    <logic:notEmpty name="<%=DefaultValue.REQUEST_NOTICE_MESSAGE%>">



        <html:messages id="msg"
            name="<%=DefaultValue.REQUEST_NOTICE_MESSAGE%>" property="user.exist">
            <bean:write name="msg" />
        </html:messages>

    </logic:notEmpty>

上面的这种方法,就可以显示并输出所有的你放到ActionMessages里面的消息。

如果想在特定的地方输出你定义的消息,可以用
            <tr>

                <td>
                    username
                </td>
                <td>
                    <input type="text" name="username" value="zhangyi">
                </td>
                <td>
                    <html:messages id="msg"
                        name="<%=DefaultValue.REQUEST_NOTICE_MESSAGE%>"
                        property="user.username">
                        <bean:write name="msg" />
                    </html:messages>
                </td>
            </tr>

指定了property就可以取道你想取得的消息。这个属性,就是上面的在action中指定的属性。


效果如图:









|----------------------------------------------------------------------------------------|
                           版权声明  版权所有 @zhyiwww
            引用请注明来源 http://www.blogjava.net/zhyiwww   
|----------------------------------------------------------------------------------------|
posted on 2009-11-23 17:59 zhyiwww 阅读(637) 评论(0)  编辑  收藏 所属分类: j2ee

只有注册用户登录后才能发表评论。


网站导航: