开发者

Struts ActionMessage

开发者 https://www.devze.com 2023-01-25 00:14 出处:网络
Hi I have a struts 1.X app, and in order to show errors detected in an action class, I use: errors.add(\"Error Global\", new ActionMessage(\"some_string_in_properties_file\"));

Hi I have a struts 1.X app, and in order to show errors detected in an action class, I use:

errors.add("Error Global", new ActionMessage("some_string_in_properties_file"));

Which works just fine.

My problem is that now the st开发者_StackOverflow中文版ring I need to send to the jsp page as error has a session variable in it (like "You have 3 more valid attempts", being 3 the session variable).

How can I accomplish this ?

Thanks.


Try to use ActionMessage constructor of 2 arguments. According to JavaDoc:

public ActionMessage(java.lang.String key,
                     java.lang.Object value0)

Construct an action message with the specified replacement values.

Parameters:
    key - Message key for this message
    value0 - First replacement value

In your case:

errors.add("Error Global", new ActionMessage("some_string_in_properties_file", sessionVariable)); 

some_string_in_properties_file should look like this:

some_string_in_properties_file=You have {0} more valid attempt(s)
0

精彩评论

暂无评论...
验证码 换一张
取 消