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" />

In Above example, two action methods are called in a single form.

Let’s say configuration file contains below setting:

<?xml version="1.0" encoding="UTF-8" ?>
        "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN"


	<package name="calc" extends="struts-default">
		<action name="calculatorInput">

		<action name="calculatorResult">

		<action name="calculator_*" method="{1}"
			<result name="success" type="chain">calculatorResult</result>


If we try to access the page via action like “http://localhost:8080/DynamicMethodInvocation/calculatorInput.action”
Then the code runs fine.

When we try to access the same page directly:
Boom !!! we got error “Form action defaulting to ‘action’ attribute’s literal value”.

If you observe the jsp code clearly, you can see that there is no action attribute is set in the tag <s:form>.
So, to overcome this problem, we must specify the default action in <s:form>.

Related posts

Leave a Reply

This site uses Akismet to reduce spam. Learn how your comment data is processed.