Limited Period Offer - Upto 50% OFF | OFFER ENDING IN: 0 D 0 H 0 M 0 S

Log In to start Learning

Login via

Post By Admin Last Updated At 2020-06-15
Struts Overview
Struts OverviewWhat is Struts

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 Framework

The 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

  1. Configurable MVC components
  2. POJO based actions
  3. AJAX support
  4. Integration support
  5. Various Result Types
  6. Various Tag support
  7. 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.MVC Architecture of Structs1Advantage

  • Easy to maintain
  • Easy to extend
  • Easy to test
  • Better separation of concerns
Interceptor is a question that is summoned at the preprocessing and postprocessing of a demand. In Struts 2, interceptor is utilized to perform operations, for example, approval, special case dealing with, internationalization, showing middle of the road result and so forth.Favorable position of interceptors

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 ValueStack 

A 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 Interface

The 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 standard flowStandard flow Architecture
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.
namespace It is a discretionary quality of package. On the off chance that namespace is absent,/is expected as the default namespace. In such case, to conjure the activity class, you require thisURI: /actionName.actionOn the off chance that you indicate any namespace, you require this.URI: /namespacename/actionName.action
  • 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.
2) activity componentThe activity is the subelement of bundle and speaks to an activity.Properties of activity component
  • name is must for characterizing any activity.
class is the discretionary property of activity. On the off chance that you discard the class quality, ActionSupport will be considered as the default activity. A basic activity might be as:

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:

com.javaspot.Product">On the off chance that you need to conjure a specific technique for the activity, you have to utilize strategy property.3) result component It is the sub component of activity that indicates where to forward the demand for this activity.
  • Traits of result component
name is the discretionary trait. On the off chance that you overlook the name characteristic, achievement is accepted as the default result name.sort is the discretionary characteristic. In the event that you discard the sort quality, dispatcher is expected as the default result sort.Multiple Configuration File 

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 2) Create configuration fileswe make two setup documents that characterizes activity with comes about.struts-first.xml welcome.jspstruts-second.xml welcome.jspOther Required Resources To run this application, we require following assets:
  • jsp
  • java
  • View Components
index.jspThis jsp page makes two connections.index.jspfirst namespace|second namespace Activity class It is the basic Action class containing just execute technique.Welcome.java bundle com.javaspot;open class Welcome {open String execute(){return "achievement";}}2 view componentsThe name of 2 see segments are same i.e. welcome.jsp however both are found in an unexpected way.welcome.jsp It is situated inside the principal registry under root.

Welcome to first namespace

welcome.jsp

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).