SoFunction
Updated on 2025-03-08

Common Errors and Cause Analysis of Java Struts

1 Exception: Cannot retrieve mapping for action /Login (/Login is your action name)
Possible reasons: action is not defined again, or matching action is not found, for example, in JSP files. Handling: If the above exception occurs, please check the definition part. Sometimes it may be that the wrong character is typed or some do not comply with the rules. You can use the struts console tool to check.
2 Exception: Cannot retrieve definition for form bean null
Possible cause: This exception is because Struts does not find the form bean expected by the action based on mapping. Most of the cases may be because the name attribute set in the form-bean does not match the name attribute set in the action. In other words, both action and form should each have a name attribute and match exactly, including upper and lower case. This error will also occur when there is no name attribute and action association. If the name attribute is not specified in the action, then there is no name attribute and action association. Of course, when action creates certain controls, such as jumping to the corresponding jsp page according to the parameter value instead of processing form data, this does not use the name attribute, which is also one of the methods of using action.
3 Exception No action instance for path /xxxx could be created
Possible Causes
Special tip: Because there are many situations that will cause this error, it is recommended that you increase the log/debug level of your web server, so that you can see potential errors that occur when trying to create an action class from more information. You have already set the association in this action class (that is, added a tag).
There are many reasons why the action class specified by the class attribute of the action tag cannot be found, for example:
Locating compiled .class files failed. Failure to place compiled .class file for the action in the classpath (In web development, the location of the class is in WEB-INF/classes, so your action class must be in this directory. For example, your action class is located in WEB-INF/classes/action/, so when setting the action attribute type in it).
Spelling errors, this also happens from time to time and is not easy to find. Pay special attention to the case of the first letter and the name of the package.
The action class specified in the action class does not inherit from Stuts' Action class, or the action class you customize does not inherit from the Action class provided by Struts.
Your action class must inherit from the Action class provided by Struts.
Your classpath problem. For example, the web server does not find your resource file, and the resource file must be in the WEB-INF/classes/ directory.
4 Exception: No getter method for property username of bean
Possible Causes
There is no bit form bean to define a getter method
This error mainly occurs in FormBean submitted by form. When marked with struts, there must be a getUsername() method in FormBean. Note the letter "U".
5 Exception : Cannot find ActionMappings or ActionFormBeans collection
Possible Causes
Neither the tag that identifies the Struts actionServlet or the tag that maps the .do extension or neither is declared in it.
Typing or spelling errors in it can also lead to the occurrence of this exception. For example, a marker is missing. It is best to use the struts console tool to check it out.
In addition, load-on-startup must be declared in it, either an empty tag or a value is specified. This value is used to display the priority of the servlet operation. The larger the value, the lower the priority.
Another thing related to using load-on-startup is that using Struts to precompile JSP files may also cause this exception.
6 Exception
: Cannot find bean in any scope
Probable Causes
Trying to use child elements of form outside of Struts' form tag. This often happens when you use Struts' html tag behind it.
Also, be aware of the unintentional tag that you may use inadvertently. For example, when the web server parses, it will be regarded as a unintentional tag. All tags used subsequently are considered to be outside of this tag, if used again
Also, when using taglib to introduce HTML tag library, the value of prefix you use is not html