Struts 2 result type

When request comes, business logic is executed first and after that result is displayed as view. Struts provides a number of predefined result types. The dispatcher is the default result type. The <results> tag is used to specify a result type in sturts.xml. The dispatcher, FreeMaker and redirect are the commonly used result types. Struts … Read more

Struts 2 custom interceptor

We can create a custom interceptor in struts 2. To create a custom interceptor implements the Interceptor interface. Interceptor interface provides the methods to create a custom interceptor. Methods of Interceptor interface: 1. init(): It is used to initialize the interceptor. It is called only once by the web container. public void init() 2. intercept(ActionInvocation … Read more

Struts 2 execAndWait interceptor

execAndWait interceptor: The execAndWait interceptor is used in case of long running action. It sends the user to an intermediate waiting page while action is executed. Note: We have to put the meta refresh tag on the top of the waiting page so that waiting page will redirect to the required result page. Struts 2 … Read more

Interceptors in struts 2

Interceptors: Interceptor is an object which is called at the pre processing and post processing of a request. These are same as the filters in the servlet. Use of interceptors in struts 2. Interceptors are used to perform some pre-processing task before the action is invoked. Interceptors are used to perform some post-processing task after … Read more

Value Stack in struts 2

Valuestack in struts2 pdf download. In struts 2 ValueStack represents a stack that contains the references of application specific objects. When a request come an object of ValueStack is created first and after it object of Action, Model or any other java resources are created. The references of all these objects are maintained in ValueStack. … Read more

OGNL in struts 2

OGNL refers to Object Graph Navigation Language. It is mainly used to set or get the value of a java bean property. Use of OGNL in struts 2. As an expression language it is used in forms and response UI pages. It is used to access the objects in ValueStack. It is used in type … Read more

Multiple configuration file in Struts 2

We can break struts.xml file into multiple small files. At runtime there can be only one struts.xml for an application so other files have to be included in the default struts.xml file. Syntax: <struts> //Other attributes <include file="strutsfile1.xml"/> <include file="strutsfile2.xml"/> //Other attributes </struts><struts> //Other attributes <include file="strutsfile1.xml"/> <include file="strutsfile2.xml"/> //Other attributes </struts> Example: login.jsp <%@ … Read more

Struts 2 Hello World example

Let us start with a simple struts program to say “Hello World”. If you not have the knowledge of struts architecture and configuration files then kindly go through these first. Example: login.jsp <%@ taglib uri="/struts-tags" prefix="s"%> <html> <head> <title>Struts 2 Hello World example</title> </head> <body> <h3>This is a Hello World example.</h3>   <s:form action="Login"> <s:textfield … Read more

Action in struts 2 by extending ActionSupport class

ActionSupport class implements a no. of interfaces like Action, Validateable, LocaleProvider and Serializable etc. It is more commonly used instead of Action interface. Example: login.jsp <%@ taglib uri="/struts-tags" prefix="s"%> <html> <head> <title>Struts 2 ActionSupport class extends example</title> </head> <body> <h3>This is an ActionSupport class extends example.</h3>   <s:property value="message" /> <br/>   <s:form action="Login"> <s:textfield … Read more

Action in struts 2 by implementing Action interface

Action interface defines five constants and one no-argument method. Action interface. public interface Action { public static final String SUCCESS = "success"; public static final String NONE = "none"; public static final String ERROR = "error"; public static final String INPUT = "input"; public static final String LOGIN = "login"; public String execute() throws Exception; … Read more