Explain dynamic method invocation in Struts 2

Author posted by Jitendra on Posted on under category Categories Struts and tagged as Tags with 6 Comments on Explain dynamic method invocation in Struts 2

Explain dynamic method invocation in Struts 2

Dynamic Method invocation is the concept in the Struts action mapping file, where instead of writing <action> for every method, one can map the wild character with the method name having same prefix or suffix.

Example : Instead of writing addOperation, subOperation and divOperation, programmer can write *Operation.

Consider below jsp code:

<s:form action="calculator_add" >
<s:textfield name="num1" label="Number 1"></s:textfield>
<s:textfield name="num2" label="Number 2"></s:textfield>
<s:submit action="calculator_add" value="Add" />
<s:submit action="calculator_sub" value="Substract" />
</s:form>

Continue reading “Explain dynamic method invocation in Struts 2”

Error Resolved- Form action defaulting to ‘action’ attribute’s literal value

Error Resolved in Struts 2- Form action defaulting to ‘action’ attribute’s literal value

This Error normally comes while using Dynamic Method invocation of Struts 2.
Consider below code:

<s:form >
<s:textfield name="num1" label="Number 1"></s:textfield>
<s:textfield name="num2" label="Number 2"></s:textfield>
<s:submit action="calculator_add" value="Add" />
<s:submit action="calculator_sub" value="Substract" />
</s:form>

In Above example, two action methods are called in a single form. Continue reading “Error Resolved- Form action defaulting to ‘action’ attribute’s literal value”

Dynamic Results in Struts 2

Author posted by Jitendra on Posted on under category Categories Struts and tagged as Tags with 1 Comment on Dynamic Results in Struts 2

Example and sourcecode of creating Dynamic Results in Struts 2

In Struts 2, we can decide next action to be executed at runtime with complete set of its own interceptors.  here i will assume the example and source code of the previous article.

For this demo, change the existing Action class code:
Continue reading “Dynamic Results in Struts 2”

Step by Step Simple Login Application in Struts 2

Author posted by Jitendra on Posted on under category Categories Struts and tagged as Tags with 6 Comments on Step by Step Simple Login Application in Struts 2

Example of Simple Login Application in Struts 2

We have seen that what is struts and how it works. I will guide the new developer, step by step to create the login application using struts 2 in this article.

Step 1 : Download the struts jar file or sample application from the official struts website.

Step 2 : Create a web project for jsp and open web.xml. In web.xml add the following lines of code in between <web-app> tag.


    <filter>
	<filter-name>webwork</filter-name>
	<filter-class>
	    org.apache.struts.action2.dispatcher.FilterDispatcher
	</filter-class>
    </filter>

    <filter-mapping>
	<filter-name>webwork</filter-name>
	<url-pattern>/*</url-pattern>
    </filter-mapping>

Continue reading “Step by Step Simple Login Application in Struts 2”

What is Struts 2 and how it works

Author posted by Jitendra on Posted on under category Categories Struts and tagged as Tags with 5 Comments on What is Struts 2 and how it works

What is Struts 2 and how it works?

Struts 2 is the Open source web application Framework which simplified the creation of Web Applications in in Java. It is based on the Model – View – Framework (MVC) architect which is originally found in language “SmallTalk“.  Latest version of Struts is 2 and which is created by using concepts of WebWork and Xwork.

Flow of Struts 2:

How Struts 2 Works
How Struts 2 Works

Continue reading “What is Struts 2 and how it works”