The struts system is utilized to create MVC-based web application. The struts system was at first made by Craig McClanahan and gave to Apache Foundation in May, 2000 and Struts 1.0 was discharged in June 2001. The present stable arrival of Struts will be Struts 2.3.16.1 in March 2, 2014. This struts 2 instructional exercise covers every one of the themes of Struts Framework with disentangled cases for learners and experienced people.
Struts 2 FrameworkThe Struts 2 system is utilized to create MVC (Model View Controller) based web applications. Struts is the mix of webwork system of open symphony and struts 1.
struts2 = webwork + struts1
The Struts 2 gives backings to POJO based activities, Validation Support, AJAX Support, Integration support to different systems, for example, Hibernate, Spring, Tiles and so forth, support to different outcome sorts, for example, Free marker, Velocity, JSP.
JAVA Tutorial Video
[embed]https://www.youtube.com/watch?v=UbpbqqIw_3Q&t=1725s[/embed]Struts Features
- Configurable MVC components
- POJO based actions
- AJAX support
- Integration support
- Various Result Types
- Various Tag support
- Theme and Template support
Model 2 (MVC) Architecture
Struts 2 depends on the MVC (Model View Controller) plan design. The MVC configuration design comprises of three modules model, view and controller. Demonstrate the model speaks to the state (information) and business rationale of the application. View The view module is dependable to show information i.e. it speaks to the introduction. Controller The controller module goes about as an interface among view and model. It catches every one of the solicitations i.e. gets information and charges to Model/View to change as needs be.Advantage
- Easy to maintain
- Easy to extend
- Easy to test
- Better separation of concerns
Pluggable If we have to evacuate any worry, for example, approval, exemption taking care of, logging and so forth from the application, we don't have to redeploy the application. We just need to expel the section from the struts.xml record.
Struts 2 default interceptors
Alias,autowiring,chain ,checkbox ,cookie ,conversionError ,createSession ,clearSession ,debugging ,externalRef,execandWait ,exception ,fileUpload ,i18n ,jsonValidation ,logger ,store,modeldriven ,scopedModelDriven ,params ,actionMappingParas,prepare ,profiling ,roles ,scope ,servletConfig ,sessionAutowiring,staticParams,timer ,token,tokenSession ,validation ,workflow,annotationWorkflow, multiselect.Struts 2 ValueStackA value Stack is essentially a stack that contains application particular questions, for example, activity objects and other model protest. At the execution time, activity is put on the highest point of the stack. We can place protests in the valuestack, question it and erase it.
ValueStack Interface The struts 2 system gives an interface to manage valuestack. It gives numerous helpful strategies.Methods of ValueStack interface
public String findString(String expr) public Object findValue(String expr) public Object findValue(String expr, Class c) public Object peek()public Object pop()public void push(Object o) public void set(String key, Object value) public int size()Struts 2 ActionContext
The ActionContext is a holder of items in which activity is executed. The qualities put away in the ActionContext are one of a kind for each string (i.e. ThreadLocal). So we don't have to make our activity string safe. The ActionInvocation speaks to the execution condition of an activity. It holds the activity and interceptors objects.
Struts 2 ActionInvocationActionInvocation InterfaceThe struts structure gives ActionInvocation interface to manage ActionInvocation. It gives numerous techniques, some of them can be utilized to get the case of ValueStack, ActionProxy, ActionContext, Result.
No. | Method |
1) | publicActionContext getInvocationContext() |
2) | public ActionProxy getProxy() |
3) | public ValueStack getStack() |
4) | public Action getAction() |
5) | public void invoke() |
6) | public Result getResult() |
Struts 2 Configuration File
The struts application contains two fundamental arrangement documents struts.xml record and struts.properties document. The struts.properties record is utilized to supersede the default estimations of default.xml document gave by struts structure. So it is not obligatory. For the most part, you won't utilize struts.properties document. We will find out about it later.
1) package element
We can without much of a stretch gap our struts application into sub modules. The bundle component determines a module. You can have at least one packages in the struts.xml document.
Characteristics of package component
- name is must for characterizing any package.
- exends The package component for the most part expands the struts-default bundle where interceptors and result sorts are characterized. In the event that you broaden struts-default, every one of the activities of this bundle can utilize the interceptors and result-sorts characterized in the struts-default.xml record.
- name is must for characterizing any activity.
Technique It is a discretionary trait. On the off chance that you don't indicate technique characteristic, execute strategy will be considered as the strategy for activity class. So this code:
- Traits of result component
For a huge application, it is smarter to utilize various setup document that one with the goal that it might be anything but difficult to deal with the application.
We can make numerous arrangement documents however we have to characterize it in the struts.xml record. The includesub-component of struts is utilized to characterize the bolstered arrangement document.
Case to make various arrangement documents
We should see the straightforward case to characterize numerous setup records.1) Define entry of multiple configuration files in struts.xml
In this struts.xml record, we have characterized 2 setup documents struts-first.xml document and struts-second.xml record.The struts-first.xml record is situated inside the main catalog and struts-second.xml document is situated inside the second registry.struts.xml- jsp
- java
- View Components
Welcome to first namespace
It is situated inside the second index under root.
Welcome to second namespace
Struts 2 Multiple Namespace We can characterize numerous namespaces in struts.xml document by the namespace quality of bundle component. As we probably am aware, default namespace is (root).