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. " Exception Probable Cause Related Links " Cannot retrieve mapping for action javax.servlet.jsp.JspException: Cannot retrieve mapping for action"/Login No action defined in"struts-config.xml"to match that specified in the JSP's"<html:form action="Login.do". "

Cannot retrieve definition for form bean null Exception org.apache.jasper.JasperException: Cannot retrieve definition for form bean null This exception typically occurs because Struts cannot find the form bean it expects for a specific action according to the mapping in thestrutsconfig.xml"file. Most often, this is probably because the name given to the form in the"name"attribute of the"form-bean"element does not match the"name"attribute of the associated action's"action"element. In other words, the action and form should each have a"nameattribute that matches exactly, Probable including case. It has been reported that this error has been seen when Cause no"name"attribute is associated with the action. If there is no"name"attribute in an"action"element, 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"name"attributes in the"formbean"andaction"elements in the"struts-config.xml"file is the usual culprit. " Must specify type attribute if name is specified Exception Must specify type attribute if name is specified Probable This error is seen in conjunction with the Struts' HTML FORM tag. As the error Cause 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: 1. Remove"name"attribute altogether and specify only an"action"attribute, allowing Struts to figure out the form class from

thestruts-config.xml"file. 2. If you really want to use the"name"attribute, then specify the"type"attribute. 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 Struts FAQ / View / HTML Links " No action instance for path /xxxx"could be created Exception No action instance for path /xxxx"could be created 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.xml"file. Your Action class specified in the"struts-config.xml"file under the"class"attribute of the action mapping for action"xxxx"cannot be found for a variety of reasons, including (but not limited to):

Probable Causes

Failure to place compiled".class"file for the action in the classpath (needs to be under"WEB-INF/classes"with 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"package"keyword) does not match the spelling or complete package hierachy specified for your action class in the"class"attribute of the action in"struts-config.xml.

Action class specified in the"/xxxx"action mapping in the"strutsconfig.xml"file (class"attribute) does not extend (directly or indirectly) from the"Action"class. In other words, your custom Action class does not extend off the Struts-provided"Action"class or off of another class that eventually extends the"Action"class (such as"DispatchAction. Problem in your classpath, such as web server not being able to find"ApplicationResources.properties"files in the"WEBINF/classes/"directory or specified subdirectory. Problem in"struts-config.xml"file with action mapping. Problem with"data-sources.xml"file.

• •

Relevant Links

Application's Action classes does not extend Strutsprovided"Action"class Package hierarchy/directory structure specified in"strutsconfig.xml"file differs from that hierarchy specified in the actual action class's file using the"package"keyword. http://www.mail-archive.com/strutsuser@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.xml"file?: http://www.caucho.com/quercus/faq/section.xtp?section_id=30

" Cannot find bean under name ... Exception Cannot find bean under name ... This is usually seen in association with a problematic Struts HTML SELECT custom tag. The Struts"html:select"tag behaves differently depending whether one or both of the"name"and"property"attributes is specified for its encompassed"<html:options>"tags. If the"name"attribute is specified, whether or not if the"property"attribute is specified, then a bean matching the specified"name"will be expected in some scope (such Probable as"page,"request,"session, or"application). If the matching bean is Cause 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:options"might be associated with it. The second approach is to not specify the"name"attribute and instead use only the"property"attribute. " No getter method for property"XXXX"of bean org.apache.struts.taglib.html.BEAN javax.servlet.jsp.JspException: No getter method for property"username"of bean Exception org.apache.struts.taglib.html.BEAN No getXXXX()"method defined for form field with name"XXXX This can happen if the JSP/Struts developer forgets that the name of the"get"method will have the same spelling as the value supplied in the Struts Probable tag's"property"attribute, but that case will be different and is based on Causes JavaBean specification rules. For example, my form class should have a"getUsername"method if my Struts form-related tag has"username"as the value for its"property"attribute. Note the difference in case marked with"emphasis"on the letter "U." Related • Case can trip up the matching between get method's name and name Links 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 This error occurs typically when the specified Java".class"file 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/classes"and"/WEB-INF/lib"contents). Note that the"NoClassDefFoundError"in general typically indicates lack of the specified class in the relevant classpath. In this particular case the missing class would beActionForm.class This error is sometimes seen when one or more"ActionForm.class"instances are actually in the classpath. This most often occurs when"ActionForm.class"is made available correctly by placing"struts.jar"in the"/WEB-INF/lib"directory. When this library has been correctly placed and it is verified that"ActionForm.class"actually is present in the"struts.jar"file, the problem is either that more than one copy of"ActionForm.class"is in the classpath or (more likely) that duplicate versions of class files other thanActionForm"are in the same classpath, causing confusion. This is especially true if a class that extends"ActionForm"is made available twice, such as in an".ear"file that encompasses a".war"file as well as in the".war"file'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.

Probable Causes

Related Links

EJB and Web Shared Links: http://forum.java.sun.com/thread.jsp? forum=26&thread=413060&tstart=0&trange=15 Keep"Action"and"ActionForm"(and their children) as nonoverlapping unit(s) of an application http://www.mail-archive.com/strutsuser@jakarta.apache.org/msg47466.html http://www.mail-archive.com/strutsuser@jakarta.apache.org/msg47467.html

" Exception creating bean of class org.apache.struts.action.ActionForm: {1} javax.servlet.jsp.JspException: Exception creating bean of class Exception org.apache.struts.action.ActionForm: {1} Probable Instantiating Struts-provided"ActionForm"class directly instead of

Causes

instantiating a class derived off"ActionForm. This might occur implicitly if you specify that a form-bean is this Struts"ActionForm"class rather than specifying a child of this class for the form-bean. Not associating an"ActionForm-descended class with an"action"can also lead to this error. "

Related Links "

Cannot find ActionMappings or ActionFormBeans collection javax.servlet.jsp.JspException: Cannot find ActionMappings or Exception ActionFormBeans collection Either the <servlet> tags for the Struts action servlet or the <servlet-mapping> tags for the".do"extension mapping or both not present in the"web.xml"file. 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.xml"can lead to this error message. For example, missing a slash ("/") on a closing tag can have this Probable effect. Causes Another element that must be present in the"web.xml"file is the"load-onstartup"element. 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-startup"tags, the lower its priority. Another possibility, related to need to use"load-on-startup"tag, is that precompiling JSPs using Struts can lead to this message as well. • Explicitly Define"<load-on-startup> http://saloon.javaranch.com/cgi-bin/ubb/ultimatebb.cgi? Related ubb=get_topic&f=50&t=001055 Links http://threebit.net/tutorials/ejb/general/ " NullPointerException at ... RequestUtils.forwardURL java.lang.NullPointerException at org.apache.struts.util.RequestUtils.forwardURL(RequestUtils.java:1223) Missing"path"attribute in the"forward"subelement of the"action"element in"struts-config.xml "

Exception Probable Causes Related Links "

Cannot find bean org.apache.struts.taglib.html.BEAN in any scope javax.servlet.jsp.JspException: Cannot find bean Exception org.apache.struts.taglib.html.BEAN in any scope Probable Trying to use Struts"form"subelement tags outside of the Struts'"form"tag. Causes 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:form"tag 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"form"tag 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 " Exception Probable Causes Related Links "

Using"form"subelements outside of a"form"tag" http://forum.java.sun.com/thread.jsp? thread=337537&forum=4&message=1384153

Missing message for key"xx.xx.xx javax.servlet.jsp.JspException: Missing message for key"xx.xx.xx The key-value pair with specified key is not in"ApplicationResources.properties"file ApplicationResources.properties"file not in classpath (not in"WEB-INF/classes"directory in specified location) "

Cannot find message resources under key org.apache.struts.action.MESSAGE Exception Cannot find message resources under key org.apache.struts.action.MESSAGE Explicitly trying to use message resources that are not available (such as"ApplicationResources.properties"not available Implicitly trying to use message resources that are not available (such as using Probable empty"html:options"tag instead of specifying the options in its body -- this Causes assumes options are specified in"ApplicationResources.properties"file) XML parser issues -- too many, too few, incorrect/incompatible versions • Provide Struts with Resource Bundle http://threebit.net/tutorials/ejb/general/ • XML Parser Issues Related http://www.mail-archive.com/strutsLinks user@jakarta.apache.org/msg15779.html " No input attribute for mapping path /loginAction

No input attribute for mapping path /xxxxAction No"input"attribute in action mapping in"struts-config.xml"file for the action with the name specified in the error message. An"inputattribute is not required if form validation is not performed (either because Probable the"validate"attribute is set to"false"or because the validation method in Cause the relevant form class is not implemented. The"input"attribute 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 Strange and seemingly random characters in HTML and on screen, but not in Error original JSP or servlet. Regular HTML"form"tags intermixed incorrectly with Probable Struts"html:form"tags. Causes Encoding style used does not support characters used in page. Related Links " " "Document contained no data" or no data rendered on page "Document contained no data" in Netscape Error No data rendered (completely empty) page in Microsoft Internet Explorer Employing a descendent of the"Action"class that does not implement the"perform()"method while using the Struts 1.0 libraries. Struts 1.1Action"child classes started using"execute()"rather than"perform(), Probable but is backwards compatible and supports the"perform()"method. However, Cause 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

Error

Related Resources
• •

JSP Best Practices More JSP Best Practices

Other Useful Struts Resources
• •

Getting the Most Out of the Struts Tag Libraries Struts Custom Tag Libraries

Sign up to vote on this title
UsefulNot useful