Java Struts2 Tutorial - Introduction

 

 

Java Struts2 Tutorial - Introduction

 

What is Struts in Java?

Apache Struts is an open-source web application framework for developing an enterprise-level web applications in Java EE. It is  built on model–view–controller architecture. It uses and extends the Java Servlet API and also uses other Java technologies like JSP, XML, JSTL etc. It was originally created by Craig McClanahan. Latter, it is given to the Apache Foundation in May 2000.  

The latest version of struts is Struts 2.5.22.



Struts web-MVC framework allows separating Model, View, Controller components easily.
Struts, written in java. It works with different technologies such as Java Servlets, JavaBeans, XML, and many more.


Controller: maps user request  to action. Incoming request of the application are processed by Controller.

Model: In struts, usually it is ActionServlet (FilterDispatcher in Struts 2.x). Hold business Logic of an application. Creates a bean to access data or to perform real functionality of application. Once the action executes, it returns a code to servlet-dispatcher to look up the view. It can be any view in a framework, or it can be dispatched to another action in a series.

View: JSP, XML, Other view technologies. This component  presents the information to the user and also collects data using input form from them.

 Communication between components:

 

e-trainings-struts-components-relation-diagram

 

Struts2 features:

 

→ struts2 is an elegant, extensible framework for building enterprise java web applications.
s2 actions are spring friendly, they allow  integrating spring easily to struts application.
Ajax theme enables to make the application more dynamic.
Configuration files allow changes and re-loadable. Without re-starting a web container, they can be updated.

Struts2 Tags

 

Generic Tags
    Control Tags: if, else, elseif, iterator       
    Data Tags: action, bean, parameter include...

UI Tags:
    form Tags: form checkbox, textfiled, password.
    Non Form UI Tags: table tree, div..

Ajax Tags
    http://strus.apache.org/2.x/docs/ajax-tags.htm


Struts2 requires


    Servlet API 2.4
    JSP API 2.0
    Java6  or above


 

I. Struts Action
 

 public class Myaction extends Action
    {
       public String executes() throws Exception{
        
            do the work
        return "success";
        }
        }



**it can have properties with getter and setters.

Action provides the common result names

"success"
"none"
"error"
"input"
cancel
"login" as constants

because of well versed Tags, many changes can be made on the fly without re-starting a web container.
                     

Action Mapping

The Tag can specify the action by name and the framework will render the
default extension and anything else that is needed.

action mapping in struts.xml

 

<struts>
    <package name="default" extends="struts-default">
        <action name="HelloWorld" class="HelloWorld">
            <result name="SUCCESS">/success.jsp</result>
        </action>
    </package>
</struts>
 

Comments

Popular posts from this blog

Recently viewed list in PHP Mysql

Import CSV File Into MySQL Using PHP

Shoppingcart using PHP Sessions - Miniproject