1. Download Fortect and install it on your computer
2. Launch the program and click "Scan"
3. Click "Repair" to fix any issues that are found
Speed up your computer's performance now with this simple download.
If you are facing struts2 error message, this guide should help.
I am in Struts 2, I am in Struts 1.
How can we associate I via an error message with a UI system (like a text field)? don’t expect the error message to be international.
ActionErrors = error new ActionErrors ();if (userName! = null && userName.length () <= 0) error.add ("userName", new ActionError ("error.userName.required"));
Name = "Username" />
In ActionSupport and use this:
addActionError (getText ("Please enter your user ID"));
Then there seems to be a global message that can be displayed in the UI with:
So, of course, how to get the same functionality in Struts 2. Please let me know.
2
Struts has many custom tags for further development, and we've already covered data tags, control tags, and user interface tags. Ce In one day, we'll look at two tags related to the response of an action class that we can use in one-way output.
- Actionerror Tag: This tag is used as part of a class validation action for digital farmland. If validation fails for a form region, we can add an error action and the Struts 2 API will route the request to
. Farther
By mkyong |
Views: 246,907 | +121 pv / w
Fortect is the world's most popular and effective PC repair tool. It is trusted by millions of people to keep their systems running fast, smooth, and error-free. With its simple user interface and powerful scanning engine, Fortect quickly finds and fixes a broad range of Windows problems - from system instability and security issues to memory management and performance bottlenecks.
1. Download Fortect and install it on your computer
2. Launch the program and click "Scan"
3. Click "Repair" to fix any issues that are found
Frequently asked question to demonstrate the use of the Struts ActionError and ActionMessage classes of your 2.
1. ActionError - used to send messages to the user about errors - displayed with . Test = "hasActionErrors ()">
2.ActionMessage - used to send informational notes to the user, which will be displayed via .
This is a simple login form that shows youAn error message (actionerror) if the username in "mkyong" is not the same, otherwise redirecting to another page and then displaying a welcome message (action message). In addition, all tag and error signals come from getting the resource plan (properties file).
1. Folder Structure
See projecting this structure
2. File
Two properties files to save current messages.
LoginAction.properties
# Welcome messageswelcome.hello = Hello# Error messageusername.required = Usually a username is requiredpassword.required = Password Required
global.properties
#World Newsglobal.username is the same as usernameglobal.password = passwordglobal.submit = Submitglobal.reset = reset
3. Action
Classic class of actions. Perform a hassle-free validation to ensure the username is indeed mkyong and set an error message with addActionError () or a success message in addActionMessage. ().
Com.mkyong.user.action package;import com.opensymphony.xwork2.ActionSupport;Public class LoginAction extends ActionSupportusernameA private channel owner;private channel password;public string getPassword ()Send the password again;invalid public password) setPassword (Stringthis.password - password;public string GetUsername ()Return login;public nullify setUsername (username string)this.username = username;// business logicpublic line run ()Return confirmationPublic "success";// check simple vacuum ()if ("mkyong" .equals (getUsername ()))addActionMessage ("You are a smart user!");anotheraddActionError ("I do not know and do not try what can hack me!");
4. View JSP
Two simple JSPs in CSS style pages to customize error messages.
login.jsp
<% @ page contentType = "text / html;%><% @ charset = UTF-8 "taglib prefix =" s "uri =" / struts-tags "%> Struts 2 ActionError And ActionMessage Example
Action = "check user">
welcome.jsp
<% @ form contentType = "text / html;%><% @ charset = UTF-8 "taglib prefix =" s "uri =" / struts-tags "%> Struts 2 Action Errors Struts 2 Example And ActionMessage
:
5. Struts.xml
Tie everyone together.
pages / login.jsp pages / welcome.jsp pages / login.jsp
In Struts 2, the functionality and usage of ActionError & Are actionmessage is very similar to Struts 1.
6. Run
http: // localhost: 8080 / Struts2Example / user / login.action
Username is invalid More specifically, an error with the message
Username is valid, show authorized message
Link
< ol>
Documentation ValidationAware