Why does "return ERROR" only work with exceptions?
- by ThreaT
In the struts.xml I use:
<result name="error">error</result>
Then in my action I use:
addActionError("ERROR RETURNED");
return ERROR;
When I submit the form then it just goes to a blank page and does nothing. However, if I FORCE an exception to be thrown in the action then it goes to the error page and shows the ActionError message. So am I doing this wrong? If so, how should I tell struts to show an error page using "if statements" instead of relying solely on expensive try catches?
EDIT 1:
I'm using struts 2 version: 2.1.8.1
EDIT 2:
For example, here is my action code that I'm using to test:
String test = "";
int number = 0;
try {
if (number == 1) {
System.out.println("number 1: " + number);
test = SUCCESS;
} else if (number == 2) {
System.out.println("number 2: " + number);
addActionError("ERROR RETURNED?");
addActionMessage("TESTTEST");
test = ERROR;
} else if (number == 3) {
System.out.println("number 3: " + number);
addActionError("ERROR RETURNED?");
addActionMessage("TESTTEST");
test = INPUT;
} else {
System.out.println("number 4: " + number);
test = LOGIN;
}
} catch (Exception e) {
addActionError("ERROR RETURNED? " + e);
}
return test;
And here is my JSP code:
<s:form action="number_save" method="post">
<s:textfield name="number" label="Enter number" />
</s:form>
<s:actionerror />
<s:fielderror />
<s:actionmessage />
EDIT 3:
Here is a longer version of my struts.xml:
<action name="number" method="numberCreate" class="NumberActionBean">
<result>number.jsp</result>
</action>
<action name="error">
<result>error.jsp</result>
</action>
<action name="number_save" method="numberSave" class="NumberActionBean">
<interceptor-ref name="defaultStack"></interceptor-ref>
<result name="success" type="redirect">index</result>
<result name="input" type="redirect">number</result>
<result name="error">error</result>
<result name="login" type="redirect">login</result>
<result name="none">number</result>
</action>
EDIT 4:
My error.jsp is simply a <s:actionerror /> tag with the general taglibs and html tags...