Common Struts Errors and Causes--Struts常见错误
2008-03-09 13:32
411 查看
Common Struts Errors and Causes
This page contains errors and exceptions commonly encountered during web application development using Struts. Along with the exception or error messages themselves, potential causes of these errors are often listed along with links to additional resources.
To find the error you're looking for, use your browser's Find or Search capability and input a few words that you are seeing in your error message.
More JSP Best Practices
Struts Custom Tag Libraries
This page's URI is: http://www.geocities.com/dustinmarx/SW/struts/errors.html
This page contains errors and exceptions commonly encountered during web application development using Struts. Along with the exception or error messages themselves, potential causes of these errors are often listed along with links to additional resources.
To find the error you're looking for, use your browser's Find or Search capability and input a few words that you are seeing in your error message.
Cannot retrieve mapping for action | |
---|---|
Exception | javax.servlet.jsp.JspException: Cannot retrieve mapping for action /Login |
Probable Cause | No action defined in struts-config.xmlto match that specified in the JSP's <html:form action="Login.do". |
Related Links |
Cannot retrieve definition for form bean null | |
---|---|
Exception | org.apache.jasper.JasperException: Cannot retrieve definition for form bean null |
Probable Cause | This exception typically occurs because Struts cannot find the form bean it expects for a specific action according to the mapping in the struts-config.xmlfile. Most often, this is probably because the name given to the form in the nameattribute of the form-beanelement does not match the nameattribute of the associated action's actionelement. In other words, the action and form should each have a nameattribute that matches exactly, including case. It has been reported that this error has been seen when no nameattribute is associated with the action. If there is no nameattribute in an actionelement, no form is associated with the action. Others have reported this error as merely a symptom of something completely unrelated (all too common), but the mismatch of nameattributes in the form-beanand actionelements in the struts-config.xmlfile is the usual culprit. |
Must specify type attribute if name is specified | |
---|---|
Exception | Must specify type attribute if name is specified |
Probable Cause | This error is seen in conjunction with the Struts' HTML FORM tag. As the error message points out, the "name" attribute was used in the Struts HTML FORM tag (<html:form>), but the "type" attribute was not specified for this HTML FORM custom tag. There are two easy ways to get around this: Remove nameattribute altogether and specify only an actionattribute, allowing Struts to figure out the form class from the struts-config.xmlfile. If you really want to use the nameattribute, then specify the typeattribute. This attribute should be set to the fully qualified (full package) class name of the class that is to be used as the ActionForm associated with the action. For example, the class attribute might be specified in the Struts HTML FORM tag as follows: <html:form action="someAction.do" name="MyFormBean" class="org.someOrg.someApp.someClass"> |
Relevant Links | Struts FAQ / View / HTML |
No action instance for path /xxxx could be created | |
---|---|
Exception | No action instance for path /xxxx could be created |
Probable Causes | Special Note: Because so many different things can cause this error, it is recommended that you turn your error logging/debugging levels on your web server to a high level of verbosity to see the underlying problems in trying to instantiate the action class you have written and associated with the specified action xxxx through an action mapping in the struts-config.xmlfile. |
Your Action class specified in the struts-config.xmlfile under the classattribute of the action mapping for action xxxx cannot be found for a variety of reasons, including (but not limited to): Failure to place compiled .classfile for the action in the classpath (needs to be under WEB-INF/classeswith the appropriate directory structure underneath this that matches the package your Action class belongs to). Package spelling or hierarchy specified in your action class itself (using the packagekeyword) does not match the spelling or complete package hierachy specified for your action class in the classattribute of the action in struts-config.xml. | |
Action class specified in the /xxxx action mapping in the struts-config.xmlfile ( classattribute) does not extend (directly or indirectly) from the Actionclass. In other words, your custom Action class does not extend off the Struts-provided Actionclass or off of another class that eventually extends the Actionclass (such as DispatchAction. | |
Problem in your classpath, such as web server not being able to find ApplicationResources.propertiesfiles in the WEB-INF/classes/directory or specified subdirectory. | |
Problem in struts-config.xmlfile with action mapping. | |
Problem with data-sources.xmlfile. | |
Relevant Links | Application's Action classes does not extend Struts-provided Actionclass Package hierarchy/directory structure specified in struts-config.xmlfile differs from that hierarchy specified in the actual action class's file using the packagekeyword. http://www.mail-archive.com/struts-user@jakarta.apache.org/msg65874.html Action Mapping mistake in struts-config.xml: http://www.manning.com/ao/readforum.html?forum=siaao&readthread=177 data-sources.xmlfile?: http://www.caucho.com/quercus/faq/section.xtp?section_id=30 |
Cannot find bean under name ... | |
---|---|
Exception | Cannot find bean under name ... |
Probable Cause | This is usually seen in association with a problematic Struts HTML SELECT custom tag. The Struts html:selecttag behaves differently depending whether one or both of the nameand propertyattributes is specified for its encompassed <html:options>tags. If the nameattribute is specified, whether or not if the propertyattribute is specified, then a bean matching the specified namewill be expected in some scope (such as page, request, session, or application). If the matching bean is not found in any available scope, the error above will be seen. There are two ways to address this. The first approach is to put a bean in one of the scopes so that the html:optionsmight be associated with it. The second approach is to not specify the nameattribute and instead use only the propertyattribute. |
No getter method for property XXXX of bean org.apache.struts.taglib.html.BEAN | |
---|---|
Exception | javax.servlet.jsp.JspException: No getter method for property username of bean org.apache.struts.taglib.html.BEAN |
Probable Causes | No getXXXX() method defined for form field with name XXXX |
This can happen if the JSP/Struts developer forgets that the name of the getmethod will have the same spelling as the value supplied in the Struts tag's propertyattribute, but that case will be different and is based on JavaBean specification rules. For example, my form class should have a getUsernamemethod if my Struts form-related tag has usernameas the value for its propertyattribute. Note the difference in case marked with emphasis on the letter "U." | |
Related Links | Case can trip up the matching between get method's name and name specified in Struts tag http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=58&t=000163 |
java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm | |
---|---|
Error | java.lang.NoClassDefFoundError: org/apache/struts/action/ActionForm |
Probable Causes | This error occurs typically when the specified Java .classfile cannot be located in the classpath. If this occurs at runtime of a web application (error shows on browser rather than a rendered page), this typically means that specified class is not in the web server's classpath (made up primarily of /WEB-INF/classesand /WEB-INF/libcontents). Note that the NoClassDefFoundErrorin general typically indicates lack of the specified class in the relevant classpath. In this particular case the missing class would be ActionForm.class |
This error is sometimes seen when one or more ActionForm.classinstances are actually in the classpath. This most often occurs when ActionForm.classis made available correctly by placing struts.jarin the /WEB-INF/libdirectory. When this library has been correctly placed and it is verified that ActionForm.classactually is present in the struts.jarfile, the problem is either that more than one copy of ActionForm.classis in the classpath or (more likely) that duplicate versions of class files other than ActionFormare in the same classpath, causing confusion. This is especially true if a class that extends ActionFormis made available twice, such as in an .earfile that encompasses a .warfile as well as in the .warfile's own classpath ( /WEB-INF/classes). This problem can be resolved by guaranteeing that there are no redundant classes, especially those related to Struts (directly from Struts or extensions of Struts), in the web application's view. | |
Related Links | EJB and Web Shared Links: http://forum.java.sun.com/thread.jsp?forum=26&thread=413060&tstart=0&trange=15 Keep Actionand ActionForm(and their children) as non-overlapping unit(s) of an application http://www.mail-archive.com/struts-user@jakarta.apache.org/msg47466.html http://www.mail-archive.com/struts-user@jakarta.apache.org/msg47467.html |
Exception creating bean of class org.apache.struts.action.ActionForm: {1} | |
---|---|
Exception | javax.servlet.jsp.JspException: Exception creating bean of class org.apache.struts.action.ActionForm: {1} |
Probable Causes | Instantiating Struts-provided ActionFormclass directly instead of instantiating a class derived off ActionForm. This might occur implicitly if you specify that a form-bean is this Struts ActionFormclass rather than specifying a child of this class for the form-bean. |
Not associating an ActionForm-descended class with an actioncan also lead to this error. | |
Related Links |
Cannot find ActionMappings or ActionFormBeans collection | |
---|---|
Exception | javax.servlet.jsp.JspException: Cannot find ActionMappings or ActionFormBeans collection |
Probable Causes | Either the <servlet> tags for the Struts action servlet or the <servlet-mapping> tags for the .doextension mapping or both not present in the web.xmlfile. I saw a case where the web.xml file had no elements other than the root element and so this error was occurring. |
Typos or spelling errors in the struts-config.xmlcan lead to this error message. For example, missing a slash ("/") on a closing tag can have this effect. | |
Another element that must be present in the web.xmlfile is the load-on-startupelement. This can be either an empty tag or can have an integer specified that indicates the priority of executing the associated servlet. The higher the number in the load-on-startuptags, the lower its priority. | |
Another possibility, related to need to use load-on-startuptag, is that precompiling JSPs using Struts can lead to this message as well. | |
Related Links | Explicitly Define <load-on-startup> http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi?ubb=get_topic&f=50&t=001055 http://threebit.net/tutorials/ejb/general/ |
NullPointerException at ... RequestUtils.forwardURL | |
---|---|
Exception | java.lang.NullPointerException at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1223) |
Probable Causes | Missing pathattribute in the forwardsubelement of the actionelement in struts-config.xml |
Related Links |
Cannot find bean org.apache.struts.taglib.html.BEAN in any scope | |
---|---|
Exception | javax.servlet.jsp.JspException: Cannot find bean org.apache.struts.taglib.html.BEAN in any scope |
Probable Causes | Trying to use Struts formsubelement tags outside of the Struts' formtag. Note that this might be because you are using the Struts htmltags after the closing </html:form>tag. Note that if you accidentaly make your opening html:formtag a no-body tag (you put a closing / at the end so that it looks something like <html:form ... />), this may be treated by your web server's parser as a no-body tag and everything after that tag you meant to be an opening tag will be outside of the formtag by default. Note your prefix may be different than html, but most people seem to use that as their prefix for the Struts HTML tags library. |
Related Links | Using formsubelements outside of a formtag http://forum.java.sun.com/thread.jsp?thread=337537&forum=4&message=1384153 |
Missing message for key xx.xx.xx | |
---|---|
Exception | javax.servlet.jsp.JspException: Missing message for key xx.xx.xx |
Probable Causes | The key-value pair with specified key is not in ApplicationResources.propertiesfile |
ApplicationResources.propertiesfile not in classpath (not in WEB-INF/classesdirectory in specified location) | |
Related Links |
Cannot find message resources under key org.apache.struts.action.MESSAGE | |
---|---|
Exception | Cannot find message resources under key org.apache.struts.action.MESSAGE |
Probable Causes | Explicitly trying to use message resources that are not available (such as ApplicationResources.propertiesnot available |
Implicitly trying to use message resources that are not available (such as using empty html:optionstag instead of specifying the options in its body -- this assumes options are specified in ApplicationResources.propertiesfile) | |
XML parser issues -- too many, too few, incorrect/incompatible versions | |
Related Links | Provide Struts with Resource Bundle http://threebit.net/tutorials/ejb/general/ XML Parser Issues http://www.mail-archive.com/struts-user@jakarta.apache.org/msg15779.html |
No input attribute for mapping path /loginAction | |
---|---|
Error | No input attribute for mapping path /xxxxAction |
Probable Cause | No inputattribute in action mapping in struts-config.xmlfile for the action with the name specified in the error message. An inputattribute is not required if form validation is not performed (either because the validateattribute is set to falseor because the validation method in the relevant form class is not implemented. The inputattribute specifies the page leading to this action because that page is used to display error messages from the form validation. |
Related Links |
Strange Output Characters | |
---|---|
Error | Strange and seemingly random characters in HTML and on screen, but not in original JSP or servlet. |
Probable Causes | Regular HTML formtags intermixed incorrectly with Struts html:formtags. |
Encoding style used does not support characters used in page. | |
Related Links |
"Document contained no data" or no data rendered on page | ||
---|---|---|
Error | "Document contained no data" in Netscape | |
No data rendered (completely empty) page in Microsoft Internet Explorer | ||
Probable Cause | Employing a descendent of the Actionclass that does not implement the perform()method while using the Struts 1.0 libraries. Struts 1.1 Actionchild classes started using execute()rather than perform(), but is backwards compatible and supports the perform()method. However, if you write an Action-descended class for Struts 1.1 with an execute()method and try to run it in Struts 1.0, you will get this "Document contained no data" error message in Netscape or a completely empty (no HTML whatsoever) page rendered in Microsoft Internet Explorer. | |
Related Links |
Related Resources
Other Works by the Author
JSP Best PracticesMore JSP Best Practices
Other Useful Struts Resources
Getting the Most Out of the Struts Tag LibrariesStruts Custom Tag Libraries
This page's URI is: http://www.geocities.com/dustinmarx/SW/struts/errors.html
相关文章推荐
- Android笔记 - 常见错误解决方法 | Android common erros and solutions
- Struts常见错误汇总
- struts2.5框架使用通配符指定方法(常见错误)
- Struts常见错误汇总
- J2EE综合—Struts常见错误的全面汇总
- 10大SQL编程常见错误(Ten Common SQL Programming Mistakes)
- Struts常见错误及原因分析
- C# ErrorsAndExceptions- 错误与异常的学习-《C#高级编程》学习笔记
- Struts常见错误及原因
- Struts常见错误汇总
- java开源框架集成常见错误之spring2.5中没有org.springframework.web.struts.DelegatingActionProxy ,使得Action不能注入到spring中
- Struts常见错误汇总
- Struts常见错误及原因
- struts常见的错误
- How to avoid common errors and make program efficient.
- Linux常见错误_tar: Exiting with failure status due to previous errors
- kafka集群中常见错误的解决方法:kafka.common.KafkaException: Should not set log end offset on partition
- struts 2 报错Could not find action or resul 常见错误原因分析
- Struts常见错误及原因分析
- Hibernate + Spring + Struts中的一个常见错误