| |

VerySource

 Forgot password?
 Register
Search
View: 631|Reply: 4

A Struts issue, urgent, online etc ...

[Copy link]

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

Post time: 2020-1-11 17:20:01
| Show all posts |Read mode
After the struts is verified on the action side, the error information should be returned to the page. If I want to write the code to get the error information, I mainly want to get the property of the field where the error occurred. I wonder if there is any way to get it?

My intention: to get the property of the field where the error occurred, such as userName, in addition to using <html: errors /> to display the error, I also want to highlight the error field

Thank you!!
Reply

Use magic Report

0

Threads

39

Posts

23.00

Credits

Newbie

Rank: 1

Credits
23.00

 China

Post time: 2020-1-16 12:00:01
| Show all posts
highlight is controlled by CSS
Reply

Use magic Report

1

Threads

21

Posts

19.00

Credits

Newbie

Rank: 1

Credits
19.00

 China

Post time: 2020-1-16 15:27:01
| Show all posts
Still don't understand what you mean.
I assume you are verifying via actionform
Struts adds an error set to the request if something goes wrong
In addition to using html: errors on your page, you can also use <% request.getAttribute (xxxxxxx)%> to determine and handle it.
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-16 17:45:01
| Show all posts
The highlight is indeed controlled by CSS, but how do I catch the wrong domain on the JSP page?
such as:
<div id = "userName _"> User Name: <html: text property = "userName" value = "" /> </ div>

If the verification is wrong, then you can display the error message through html: errors, but I also want to capture which area is wrong by my code, such as userName, so you can change the CSS of <div id = "userName _"> Or style to highlight. The question is, how can I catch which area is wrong with my own code.

If request.getAttribute (xxxxxxx) is used, what does xxxxxxx represent?

Thank you!
Reply

Use magic Report

1

Threads

3

Posts

4.00

Credits

Newbie

Rank: 1

Credits
4.00

 China

 Author| Post time: 2020-1-17 20:27:01
| Show all posts
I have solved the problem, thank you!

Enumeration e = request.getAttributeNames ();
while (e.hasMoreElements ()) {
String key = (String) e.nextElement ();
if (key == Globals.ERROR_KEY) {
Object value = request.getAttribute (key);
ActionErrors errors = (ActionErrors) value;
String errorsString = errors.toString ();
                           System.out.println (errorsString);
                     }
                 }

All error information is in the request.
Reply

Use magic Report

You have to log in before you can reply Login | Register

Points Rules

Contact us|Archive|Mobile|CopyRight © 2008-2023|verysource.com ( 京ICP备17048824号-1 )

Quick Reply To Top Return to the list