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.
Let’s say configuration file contains below setting:
<?xml version="1.0" encoding="UTF-8" ?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <package name="calc" extends="struts-default"> <action name="calculatorInput"> <result>/pages/calculator.jsp</result> </action> <action name="calculatorResult"> <result>/pages/calculatorResult.jsp</result> </action> <action name="calculator_*" method="{1}" class="com.G2.Actions.CalculatorAction"> <result name="success" type="chain">calculatorResult</result> </action> </package> </struts>
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:
“http://localhost:8080/DynamicMethodInvocation/pages/calculator.jsp”
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>.
Leave a Reply