Struts1 provided the facility of having related action methods in a Single Action class,depending on the method parameter, the mapped methods were executed.To achieve this we have to extend the DispatchAction class in Struts1.But this comes as default in Struts2, We need to provide the qualified methods in the action class( no need to inherit any class), and provide the mapping of action path/name to the method attribute in action tag(struts.xml) and proper code in view layer.
In the first wayretrieve the HttpServletRequest from the ActionContext object and retrieve the parameters the usual way. Code
ActionContext context=(ActionContext)invocation.getInvocationContext(); HttpServletRequest request=(HttpServletRequest)context.get(StrutsStatics.HTTP_REQUEST); String username=(String)request.getParameter(“user”);
The second wayis pretty much the Struts2, by invoking the getParameters method on context object. Code
ActionContext context=(ActionContext)invocation.getInvocationContext(); Map requestParameters=context.getParameters(); String usernames=((String)m.get(“user”));
As you can see the map doesn’t return the parameter as String unlike the Servlet specification, but an array of String (can be convinient for multivalued UI controls check box,single value UI controls data can be retrived as in above code ).
An abstract package usually defines inheritable components such as intercetpor,different interceptor stacks,result types etc.But doesn’t contain any actions.The way we declare a package as abstract is through the package elements attribute as abstract and setting the value to “true”. By default ( if abstract attribute is not mentioned) it is false.Struts-default.xml is an example of abstract package.
Struts2 doesn’t mind if the action classes doesn’t implement the Action interface, to have the execute method executed on default action method selection.Even though it appears that Action interfaces has the execute method declaration and one must implement it to have the execute method overriden in the action classes,Struts2 takes it as an informal contract with the developer by letting the developer to have an execute method conforming to the signature of execute method.Whenever Struts2 finds any voilation to the declaration of the method in unimplemented action class it throws the exeception.
A tiles-def.xml is used as a configuration file for an appliction during tiles development. You can define the layout, header, footer, body content for your View.
The validation.xml file is used to declare sets of validations that should be applied to Form Beans. Each Form Bean you want to validate has its own definition in this file. Inside that definition, you specify the validations you want to apply to the Form Bean’s fields.
Instead of having hard-coded error messages in the framework, Struts Validator allows you to specify a key to a message in the ApplicationResources.properties (or resourcebundle.properties) file that should be returned if a validation fails.