Common Struts Errors

The below article provide the common struts errors and how to rectify them.

1.The class referenced by the struts action does not exist

 To execute every action in the configuration file must have a corresponding Java class. When the class does not exist, the web server will fall to start. Say the Java class is an example.

When the web server is started, the web server will fail to load the web application.

2.The method referenced by the struts action does not exist and the name of a property does not match the case of the getter or setter methods

Struts configuration file does not exist when the name of a method in an action, then the action will not execute. In order to find there is an error message displayed, but encounting this error requires the programmer to get all the way through the   write, Compile, display test. If it is at the end or middle of lengthy work flow, then the time required finding and the typo is disproportionately large compared to the ease to fix and automatically detect the error.

Struts will map a property to the getter and better for a class attribute in an action class. The property ‘html’ would map to the getter ‘get HTML’ and not ‘get HTML’ as some developer conventions would follow. It is a confusing error for a beginner and easily missed by all.

3.The selected method was not created for a select  list and the action references in a form does not exist

The struts select tag requires two sets of getter/setter methods. One for the list or map that populates the selection options and another will represent the options that selected. The

Selected method requires a name based on the select tag name attribute. The options method requires a name based on the select tag list attribute. If they are mixed, then the implementation will not work as expected.

When the form is executed an exception is thrown after the forms execution. The error is explicit. But   finding this requires the write, compile, deploy test cycle be completed.

4.The Action referenced in a redirect does not exist and   the method or property referenced on a redirect in the action mapping configuration does not exist

This time the action is referenced from an action result within the configuration file. In the struts configuration the name of the action is misspelled and an error will be encountered after the success result is returned from the action.

When redirecting an action it is possible to pass data from one action to another or to set a parameter in the target action of the redirected. Testing this can reveal the error.

5.The package mentioned in the struts configuration does not exist and Struts Validation files must be named after the corresponding action

When redirecting an action the package is required as a parameter in the result if the action occurs   in a separate package. If this package does not exist, then testing the application will produce 401 errors.  Struct configuaration example,

…
<package name=”test” namespace=”/test” extends=”struts-default”>
<action name=”Test” class=”example.actions.TestAction”>
<result name=”success” type=”redirectAction”>
<param name=”actionName”>Test</param>
<param name=”namespace”>Test</param>
</result>
</action>
</package>

One of the ways that Apache struts provides for doing validation is by using an XML configuration files In this  case ,these XML files are in the same package as the action. It must have a name of the action class. If the action file name is ‘Test action java’ then the name of the XML file must be test action validation’ XML.

6.Struts Action returns value that is not mapped as a result and Struts Action and Interceptors require a zero argument constructor

An exception occurs when an action returns a result value not in the configuration file for the action. This is an easy error to find once encountered.

It requires a complete write-compile-deploy- test cycle

Struts cannot construct when an action class does not contain a zero argument constructor. They    believe that the zero argument constructors are always present in Java. (Which is not the case?)

7.Within JSP text, the Markup to Call a Getter is ${} instead of %{}

When a JSP tag  attribute ,the mark up to invoke a function call to get values from the Java class is to surround the name of the method with %{and}. When not within a JSP tag, the mark up is to use a & instead of a %. The difference is not initiative.HTML is a similar text markup language. Unless one knows the trick, the solution to this can be hard to find.

8.Within a Redirect Action, any passed parameter has a Getter/Setter

The web application developer has the option to pass the value of a variable to the next action when redirecting one action to another action using the redirect result type. This is accomplished by surrounding the variable name in the struts configuration value with & {and}. The mechanism used to pass the variable to the next action class involves executing the getter for the variable in one side and then executing this setter for the parameter in the redirect target action. If either of these does not exist, the action will still execute but the values will not be passed.