Struts1.2.4 learning experience! (5)

xiaoxiao2021-03-06  55

The fifth study 1. Error and information processing. First define an error message and normal information in the resource file. Such as: MessageResources, defined as follows:

Java code:

1

2 #

3 # resources

FOR TESTING TAG.

4 #

5

6 Errors.

Header =

7 Errors.

FOOTER =

Errors.

prefix =

9 Errors.

SUFFIX =

10

11 Property1Eerror1 = Property

1,

Error

1

12 Property2error1 = Property

2,

Error

1

13 property2error2 = Property

2,

Error

2

14 Property2error3 = Property

2,

Error

3

15 Property3error1 = Property

3,

Error

1

16 Property3error2 = Property

3,

Error

2

17 globalerror = Global

Error

18

19 #

20 # resources

For testing tag.

twenty one #

twenty two

.

Header =

24 messages.

FOOTER =

25

26 Property1Message1 = Property

1, Message

1

27 Property2Message1 = Property

2, Message

1

28 Property2Message2 = Property

2, Message

2

29 Property2Message3 = Property

2, Message

3

30 Property3Message1 = Property

3, Message

1

31 Property3Message2 = Property

3, Message

2

32 GlobalMessage = Global Message

33

Define errors and information classes in the program, this example is written in JSP

Java code:

1

2 <%

3 ActionerRors ErrorS =

New ActionerRors

(

);

4 Errors.

Add

("Property1",

New Actionerror

("Property1error1"

)

);

5 Errors.

Add

("Property2",

New Actionerror

("Property2error1"

)

);

6 Errors.

Add

("Property2",

New Actionerror

("Property2error2"

)

);

7 Errors.

Add

("Property2",

New Actionerror

("Property2error3"

)

);

Errors.

Add

("Property3",

New Actionerror

("Property3error1"

)

);

9 Errors.Add

("Property3",

New Actionerror

("Property3ERROR2"

)

);

Errors.

Add

ActionerRRORS.

Global_ERROR,

New Actionerror

("Globalerrror"

)

);

11 Request.

SetaTribute

(Globals.

Error_Key, Errors

);

12

13 ActionMessages Messages =

New ActionMessages

(

);

14 messages.

Add

("Property1",

New ActionMessage

("Property1Message1"

)

);

15 messages.

Add

("Property2",

New ActionMessage

("Property2Message1"

)

);

16 messages.

Add

("Property2",

New ActionMessage

("Property2Message2"

)

);

Jessages.

Add

("Property2",

New ActionMessage

("Property2Message3"

)

);

18 messages.

Add

("Property3",

New ActionMessage

("Property3Message1"

)

);

19 messages.

Add

("Property3",

New ActionMessage

("Property3Message2"

)

);

20 messages.

Add

ActionMESSAGES.

Global_Message,

New ActionMessage

("GlobalMessage"

)

);

21 Request.

SetaTribute

(Globals.

Message_Key, Messages

);

22%>

twenty three

Display error:

Java code:

1

2

3

4

Display information:

Java code:

1

2

3

4

12

5 <% = pageContext.

GetaTtribute

("msg"

)%>

6

7

8

9

10

11

13 <% = pageContext.

GetaTtribute

("msg"

)%>

14

15

16

In one

转载请注明原文地址:https://www.9cbs.com/read-113259.html

New Post(0)
CopyRight © 2020 All Rights Reserved
Processed: 0.043, SQL: 9