JAVA advanced programming: Struts Common Errors

Source: Internet
Author: User
JAVA advanced programming: Struts Common Errors-general Linux technology-Linux programming and kernel information. For details, see the following. The names of the struts-config.xml and ApplicationResources. properties files mentioned below are time-saving and need to be modified if you use multiple modules or specify different resource file names.

1. "No bean found under attribute key XXX"
An ActionForm is defined in the struts-config.xml, but the class specified by the type property does not exist, and the value of the type property should be the full name of the Form class. Alternatively, in the Action definition, the ActionForm specified by the name or attribute does not exist.

2. "Cannot find bean XXX in any scope"
In Action, some objects are usually requested. setAttribute (), and then these objects are displayed in the jsp file to be switched (using the tag or request. getAttribute () method. This exception means that jsp needs to get an object, but the previous Action does not set the object to request (or session or servletContext.
The name may be incorrect. Check that the tag in jsp is generally the name attribute, or the parameter value of the getAttribute () method; or that the setAttribute () is not executed if the Action logic is incorrect () the method is switched first.
Another possibility is that it is purely a jsp file. For example, an id value will be specified and this value will be used as the name value in the loop. If the two values are different, this exception also occurs. (The request has no corresponding object .)

3. "Missing message for key" XXX ""
If the required resources are missing, check that the ApplicationResources. properties file contains the resources required in the jsp file. For example:
  
This line of code will find the msg. name. prompt resource. If AppliationResources. properties does not have this resource, this exception will occur. When using multi-module, pay attention to specifying the name of the resource file to be used in the module's struts-config-xxx.xml, otherwise of course, what resources can not be found, this is also a very easy to make the error.

4. "No getter method for property XXX of bean teacher"
This exception message clearly states that the attribute of a bean should be obtained in jsp, but this bean does not. You should check the property attribute value of a tag in jsp. For example, the cade in the following code should be changed to code:
  

5. "Cannot find ActionMappings or ActionFormBeans collection"
To be resolved.

6. "Cannot retrieve mapping for action XXX"
In the. jsp
Action = '/XXX' is specified in the tag, but this Action is not set in the struts-config.xml.

7. HTTP Status 404-/xxx. jsp
The path attribute of Forward does not point to the jsp page. Check the path and module. For Action redirection in the same module, the path should not contain the module name; for inter-module redirection, remember to use contextRelative = "true ".

8. No exception information is displayed. a blank page is displayed.
It may be that the forward used in the Action does not match the forward name defined in the struts-config.xml.

9. "The element type" XXX "must be terminated by the matching end-tag" XXX "."
This is the format error of the struts-config.xml file, carefully check whether it is a good xml file, the xml file format here will not go into detail.

10. "Servlet. init () for servlet action threw exception"
Generally, this exception will be followed by an exception stack information about ActionServlet, which indicates the specific line of the exception that appears in the code. A prompt I encountered was as follows:

Java. lang. NullPointerException
At org. apache. struts. action. ActionServlet. parseModuleConfigFile (ActionServlet. java: 1003)
At org. apache. struts. action. ActionServlet. initModuleConfig (ActionServlet. java: 955)

To solve the problem, download the struts source code package, insert a breakpoint in row 1,003rd of ActionServlet. java, and monitor the variables. Very shameful, I lost the struts-config.xml file, so the above exception, should be synchronized with CVS accidentally deleted.

11. "Resources not defined for Validator"
This is an exception that may occur when the Validator plug-in is used for verification. In this case, you need to check the validation. xml file to see if the resources used in the file are indeed defined, and whether the form name is correct.
Related Article

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.