What is Struts Flow?

Answers were Sorted based on User's Feedback



What is Struts Flow?..

Answer / rajkumar

ActionServlet acts as a back bone to all the Struts
applications.
Flow:

-->First the request is handled by the either doGet()/doPost
() method of the Action Servlet and it calls the process()
mthod of its own.This method gets the Current Request
Processor associated with the request.

-->Then this request preocessor calls its preocess() method.
(Note:RequestProcessor also one type of Servlet).
This is the actaul place where the request is handled.

-->This method reads the struts-config.xml file and find
outs the Action class by seeing the request url path.
for ex:
incoming request trl path is:/login

struts-config.xml:

<action path="/login" type="Test.LoginClass">
<forward name="Succes" path="/Welcome.jsp"/>
<forward name="failure" path="/Login.jsp"/>
</action>

-->After identifying the Actio class it checks the whether
the request is associtaed with any form bean.This can be
checked by usin the name attribute of athe action element
from the struts-config.xml.

Ex:<form-beans>
<form name="loginForm" type="Test.LoginForm"/>
</form-beans>
<action-mappings>
<action path="/login"type="Test.LoginClass"
name="loginForm">
....
....
</action-mappings>

-->Then it creates the instance of ActionForm and calls the
corresponding getter and setter methods for the incoming
request parameters.Optionally we can validate the request
parameter by calling the validate()method in ActionForm.For
this we need to specify validate="true" and
input="/Login.jsp" in struts-config.xml file.

-->Now the actual request is handled by the Action class by
calling the execute() method.Output of this method
indicates the response of the request.The return type of
this request is ActionMappings ....

Is This Answer Correct ?    169 Yes 15 No

What is Struts Flow?..

Answer / pradeep c

the flow execution of struts.

The browser makes a request to the Struts application that
is processed by ActionServlet (Controller).

ActionServlet (Controller) populates the ActionForm (View)
object with HTML form data and invokes its validate( )
method.

ActionServlet (Controller) executes the Action object
(Controller).

Action (Controller) interfaces with model components and
prepares data for view.

Action (Controller) forwards control to the JSP (View).

JSP (View) uses model data to generate a response to the
browser.

Is This Answer Correct ?    76 Yes 29 No

What is Struts Flow?..

Answer / sandeep garg

ActionServlet acts as a back bone to all the Struts
applications.
Flow:

-->First the request is handled by the either doGet()/doPost
() method of the Action Servlet and it calls the process()
mthod of its own.This method gets the Current Request
Processor associated with the request.

-->Then this request preocessor calls its preocess() method.
(Note:RequestProcessor also one type of Servlet).
This is the actaul place where the request is handled.

-->This method reads the struts-config.xml file and find
outs the Action class by seeing the request url path.
for ex:
incoming request trl path is:/login

struts-config.xml:

<action path="/login" type="Test.LoginClass">
<forward name="Succes" path="/Welcome.jsp"/>
<forward name="failure" path="/Login.jsp"/>
</action>

-->After identifying the Actio class it checks the whether
the request is associtaed with any form bean.This can be
checked by usin the name attribute of athe action element
from the struts-config.xml.

Ex:<form-beans>
<form name="loginForm" type="Test.LoginForm"/>
</form-beans>
<action-mappings>
<action path="/login"type="Test.LoginClass"
name="loginForm">
....
....
</action-mappings>

-->Then it creates the instance of ActionForm and calls the
corresponding getter and setter methods for the incoming
request parameters.Optionally we can validate the request
parameter by calling the validate()method in ActionForm.For
this we need to specify validate="true" and
input="/Login.jsp" in struts-config.xml file.

-->Now the actual request is handled by the Action class by
calling the execute() method.Output of this method
indicates the response of the request.The return type of
this request is ActionMappings ....

Is This Answer Correct ?    36 Yes 8 No

What is Struts Flow?..

Answer / archana dandwate

Actually struts use MVC(model VIew Controller)
Archietecture.

In struts we have to define following things:
1. index.jsp(it takes input from user suppose username)
2.ActionServlet class
3.Action class
4.displayname.jsp(it display username)
---------------------
we need to change 2 file
5.struts-config.xml
6.web.xml
---------------
Lets Start with step one. we will create the view file
named index.jsp


<%@ page language="java" %>
<%@ taglib uri="/WEB-INF/struts-html.tld" prefix="html" %>

<html>
<head>
<title>Sample Struts Application</title>
</head>
<body>
<html:form action="Name" name="nameForm"
type="example.NameForm">
<table width="80%" border="0">
<tr>
<td>Name:</td>
<td><html:text property="name" /></td>
</tr>
<tr>
<td><html:submit /></td>
</tr>
</table>
</html:form>
</body>
</html>
-----------------------------------------

Note:
here we write tag like <html:form> because its struts
specific form tag.
In the Form tags the attributes you can find some
attributes defined in we will go through it.

action : Represents the URL to which this form will be
submitted. This attribute is also used to find the
appropriate ActionMapping in the Struts configuration file,
which we will describe later in this section. The value
used in our example is Name, which will map to an
ActionMapping with a path attribute equal to Name.

name :Identifies the key that the ActionForm will be
referenced by. We use the value NameForm. An ActionForm is
an object that is used by Struts to represent the form data
as a JavaBean. It main purpose is to pass form data between
View and Controller components. We will discuss NameForm
later in this section.
type :Names the fully qualified class name of the form bean
to use in this request. For this example, we use thevalue
example.NameForm, which is an ActionForm object containing
data members matching the inputs of this form.

To use the HTML tags, you must first add a taglib entry in
the application’s web.xml file that references the URI /WEB-
INF/struts-html.tld. This TLD describes all of the tags in
the HTML tag library. The following snippet shows the
<taglib> element that must be added to the web.xml file:

<taglib>
<taglib-uri>/WEB-INF/struts-html.tld</taglib-uri>
<taglib-location>/WEB-INF/struts-html.tld</taglib-location>
</taglib>
--------------------------------------------

The struts-html.tld is placed in the /WEB_INF directory.

Next Step is to create the action form

The ActionForm used in this example contains a single data
member that maps directly to the name input parameter of
the form defined in the index.jsp View. When an
<html:form/> is submitted, the Struts framework populates
the matching data members of the ActionForm with the values
entered into the <html:input/> tags. The Struts framework
does this by using JavaBean reflection. The accessors of
the ActionForm must follow the JavaBean standard naming
convention for example

The NameForm.java file is shown below
NameForm.java

package example;
//import statements
import javax.servlet.http.HttpServletRequest;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionMapping;

public class NameForm extends ActionForm {
private String name = null;
public String getName() {
return (name);
}
public void setName(String name) {
this.name = name;
}
public void reset(ActionMapping mapping,
HttpServletRequest request) {
this.name = null;
}
}
To deploy the NameForm to our Struts application, you need
to compile this class, move it to the /WEB-
INF/classes/example directory, and add the following line
to the <form-beans> section of the /WEB-INF/struts-
config.xml file:

<form-bean name="nameForm" type="example.NameForm"/>

This makes the Struts application aware of the NameForm and
how it should be referenced.

Now we create the out page for the sample application.
Lets name it diplayname.jsp
displayname.jsp

<html>
<head>
<title>Sample Struts Display Name</title>
</head>
<body>
<table width="80%" border="0">
<tr>
<td>Hello <%= request.getAttribute("NAME") %> !!
</td>
</tr>
</table>
</body>
</html>

Now we move to the step two of creating the application's
controller

In a Struts application, two components make up the
Controller. These two components are the
org.apache.struts.action.ActionServlet and the org.apache.
struts.action.Action classes. In most Struts applications,
there is one org. apache.struts.action.ActionServlet
implementation and can have many org.apache.
struts.action.Action implementations.

The org.apache.struts.action.ActionServlet is the
Controller component that handles client requests and
determines which org.apache.struts.action.Action will
process the received request. When assembling simple
applications, such as the one we are building, the default
ActionServlet will satisfy your application needs, and
therefore, you do not need to create a specialized
org.apache.struts.action.ActionServlet implementation.

The second component of a Struts Controller is the
org.apache.struts. action.Action class. As opposed to the
ActionServlet, the Action class must be extended for each
specialized function in your application. This class is
where your application’s specific logic begins.
NameAction.java

package example;

import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
import org.apache.struts.action.Action;
import org.apache.struts.action.ActionForm;
import org.apache.struts.action.ActionForward;
import org.apache.struts.action.ActionMapping;

public class NameAction extends Action {
public ActionForward execute(ActionMapping mapping,
ActionForm form,
HttpServletRequest request, HttpServletResponse response)
throws IOException, ServletException {
String target = new String("success");
if ( form != null ) {
// Use the NameForm to get the request parameters
NameForm nameForm = (NameForm)form;
String name = nameForm.getName();
}
// if no mane supplied Set the target to failure
if ( name == null ) {
target = new String("failure");
}
else {
request.setAttribute("NAME", name);
}
return (mapping.findForward(target));
}
}

Moving to step three, to deploy the NameAction to our
Struts application, we need to compile the NameAction class
and move the class file to /WEB-INF/classes/example
directory, and add the following entry to the <action-
mappings> section of the /WEB-INF/struts-config.xml file:

<action path="/Name" type="example.NameAction"
name="nameForm" input="/index.jsp">
<forward name="success" path="/displayname.jsp"/>
<forward name="failure" path="/index.jsp"/>
</action>


For step four we modify the web.xml file. We have to to
tell the Web application about our ActionServlet. This is
accomplished by adding the following servlet definition to
the /WEB-INF/web.xml file:

<servlet>
<servlet-name>action</servlet-name>
<servlet-class> org.apache.struts.action.ActionServlet
</servlet-class>
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
<load-on-startup>1</load-on-startup>
</servlet>

Once we have told the container about the ActionServlet, we
need to tell it when the action should be executed. To do
this, we have to add a <servlet-mapping> element to
the /WEB-INF/ web.xml file:

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>
----------------------------------------
important note:
You will notice in the previously listed index.jsp that our
action does not include a .do at the end of the URL. We do
not have to append the .do because it is automatically
appended if we use the <html:form /> tag. If you do not use
the <html:form /> tag, then you will need to append .do to
the action's URL. This mapping tells the Web application
that whenever a request is received with .do appended to
the URL, the servlet named action should service the
request.

Eg:
<html:form action="Name.do" name="nameForm"
type="example.NameForm">

-------------------------------------------------

Is This Answer Correct ?    26 Yes 4 No

What is Struts Flow?..

Answer / rajashree

The Apache Struts development team has announced the
creation of a new sub-project: Struts Flow. "Struts Flow
originated at the struts.sf.net project and has been
formally adopted now as a Struts subproject. Struts Flow is
a port of Apache Cocoon's Control Flow to Struts to allow
complex workflow, like multi-form wizards, to be easily
implemented using continuations-capable Javascript and
eventually Java."

Is This Answer Correct ?    22 Yes 13 No

What is Struts Flow?..

Answer / suresh

Struts is based on MVC architecuture.

1. request comes.

2. corrosponding action class will be searched in the struts.xml

3. mapped form-bean will be populated with data.

4. execute method of mapped action servlet will be executed
and result will be mapped in struts.xml with <forward> tag.

5. mapped jsp/html page with forward will be displayed.

Is This Answer Correct ?    15 Yes 7 No

What is Struts Flow?..

Answer / prabhakar

Struts Flow
===========


1) When application server gets started,container loads the
web.xml

2) When first the request is made from a JSP/HTML/XSLT to
the server with a particular URI(/something.do) the control
first reaches Web.xml file.

3) It checks the mapping for /something.do in web.xml and
finds the ActionServlet and loads ActionServlet.
......
<servlet-name>action</servlet-name>
<servlet-class>org.apache.struts.action.ActionServlet</servlet-class>
.....

<servlet-mapping>
<servlet-name>action</servlet-name>
<url-pattern>*.do</url-pattern>
</servlet-mapping>

4) As part of loading ActionServlet calls the init() as
every other servlet does.
(Note: ActionServlet extends HttpServlet only)
......................
<init-param>
<param-name>config</param-name>
<param-value>/WEB-INF/struts-config.xml</param-value>
</init-param>
........................

5) In init() it takes the init-parameters as
struts-config.xml and loads the xml file.

6) Then the ActionServlet calls the process() method of
RequestProcessor class.

7) process() method checks for the appropriate action in the
action mapping for current request and maps the URI to the
action in the struts-config.xml.

8) Then it creates an object to ActionForm associated to
that action.

9) It then calls the setters and reset() methods in the form
bean(Which extends ActionForm) corresponds to the mapped action.

10) If the action tag in struts-config.xml contains validate
"true" then the validate method is called.

11) if any validation errors it return to view component
(any jsp XSLT) which is specified as an attribute of input
"/error.jsp"

12) if there are no validation errors ,it then search for
execute method in the action class and executes it.

13) execute method performs the bussinesslogic which you
provide and returns with an ActionForward key.

14) Now the returned key is searched in the mapped action
which is specified as forward tag.

15) It looks for the appropriate view component and performs
the getters on that action form corresponding to this view
component and loads the view page in the browser.


- Prabhakar

Is This Answer Correct ?    7 Yes 1 No

What is Struts Flow?..

Answer / ranjeet srivastav

Struts is an open-source framework for building Web
applications based on the MVC pattern. Struts encourages
application architectures based on the MVC pattern and
provides services common to most Web applications.

In a Struts application, you can architect the Model layer
so that the business and data retrieval logic are easy to
reuse. This layer is responsible for running the
application's business logic and getting the relevant data
(for example, running an SQL command or reading a flat
file).

Struts encourages application architectures based on the
Model-View-Controller design paradigm. Struts provides its
own Controller component (the ActionController classes) and
integrates with other technologies to provide the Model and
the View. For the Model (Model classes), Struts can
interact with any standard data access technology,
including Enterprise Java Beans technology, JDBC, and the
Object-Relational Bridge. For the View (ActionForm
classes), Struts works well with the JavaServer Pages (JSP)
environment and other presentation systems. Figure 2
illustrates the logical flow of a Struts-based application.

Is This Answer Correct ?    7 Yes 3 No

What is Struts Flow?..

Answer / sri

The browser makes a request to the Struts application that
is processed by ActionServlet (Controller).

ActionServlet (Controller) populates the ActionForm (View)
object with HTML form data and invokes its validate( )
method.

ActionServlet (Controller) executes the Action object
(Controller).

Action (Controller) interfaces with model components and
prepares data for view.

Action (Controller) forwards control to the JSP (View).

JSP (View) uses model data to generate a response to the
browser.

Is This Answer Correct ?    9 Yes 5 No

What is Struts Flow?..

Answer / gopal g

struts is MVC(Model,View,Controller)Archietecture based
F/W software.

Resourcers OF a Struts Application In 1.0 of Struts :
---------------------------------------------------
we use following resources:

1.jsp(View)
2.Web.xml
3.struts-config.xml
4.FormBean.java (Form Bean)
5.FormAction.java(Action class)
----------------------------------
----------------------------------


Flow OF Struts Application In 1.0 of Struts :
-------------------------------------------

1).End User gives Request to Struts Application,
By Clicking on a button,in JSP(View)of our struts
Application.
2).Then,Request comes to first Web.xml
3).Now from web.xml req goes to Action servlet(Controller
Of Struts Application)
4)Then controller/Front Controller/Req Processer/Dispather
Servlet forwarads req
to Struts configaration file.
5).from there req goes to Action class via Controller
('Model' of Struts App) & it'll execute B.logic there.do so
perations with DB -->return to controller
6).And from Struts configaration file it will goes FormBean
class
via Controller.(In 1.0 of Struts)
7).From FormBean to Response goes to JSP(VIEW).

Is This Answer Correct ?    5 Yes 3 No

Post New Answer

More Struts Interview Questions

What are the cons of struts 2?

0 Answers  


How can forward action be used to restrict a strut application to mvc?

0 Answers  


what is the disadvantage of struts frame work?

11 Answers  


How you will enable front-end validation based on the xml in validation.xml?

0 Answers  


What is used to display the intermediate result in an interceptor?

0 Answers  






What is the purpose of execute() method?

0 Answers  


What is execute method in struts?

0 Answers  


what is is the use DynaActionForm?

3 Answers   TCS,


Which configuration files are used in struts?

0 Answers  


what are the componenets of struts?

8 Answers   HCL,


is it possible to see actionservlet in my system. if yes how

5 Answers  


What’s the difference between struts and turbine? What’s the difference between struts and espresso?

0 Answers  


Categories