S
Spivee
I am trying to learn Struts from the internet and some books. I found
a tutorial I am trying to follow at
http://javaboutique.internet.com/tutorials/Struts/. I get to step 8,
testing the application. Basically, you build a form and set an
action form method to forward success and failure to the original
page. Nothing special. When I hit submit, I get a blank page.
I've read a lot online and in my book, but can't figure out why it
won't forward. I'm thinking it may have to do with updates in the
struts build? Perhaps my book and the things I am reading online are
outdated?
Here are the pertinet parts of the files. Just trying to figure out
what I'm doing wrong. I have no idea how to troubleshoot this. There
are no logs, I haven't found a way to put in checks to see where it
fails etc. I'm just stumped.
web.xml - I used basically the default web.xml file from the
struts-blank application that comes with struts 1.4.2
struts-config.xml -
<struts-config>
<!-- ========== Form Bean Definitions ================= -->
<form-beans>
<form-bean name="submitForm"
type="hansen.playground.SubmitForm"/>
</form-beans>
<!-- ========== Action Mapping Definitions ============ -->
<action-mappings>
<action path="/submit"
type="hansen.playground.SubmitAction"
name="submitForm"
input="/submit.jsp"
scope="session">
<forward name="success" path="/submit.jsp" redirect="true"/>
<forward name="failure" path="/submit.jsp" redirect="true"/>
</action>
</action-mappings>
</struts-config>
Form class -
just gets and sets for each form element.
Action class -
package hansen.playground;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public final class SubmitAction extends Action {
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
System.out.println("Got here!");
SubmitForm f = (SubmitForm) form; // get the form bean
// and take the last name value
String lastName = f.getLastName();
// Translate the name to upper case
//and save it in the request object
request.setAttribute("lastName", lastName.toUpperCase());
// Forward control to the specified success target
return (mapping.findForward("success"));
}
}
The meat of the Jsp page...
<html:form action="submit.do">
Last Name: <html:text property="lastName"/><br>
Address: <html:textarea property="address"/><br>
Sex: <html:radio property="sex" value="M"/>Male
<html:radio property="sex" value="F"/>Female<br>
Married: <html:checkbox property="married"/><br>
Age: <html:select property="age">
<htmlption value="a">0-19</htmlption>
<htmlption value="b">20-49</htmlption>
<htmlption value="c">50-</htmlption>
</html:select><br>
<html:submit/>
</html:form>
a tutorial I am trying to follow at
http://javaboutique.internet.com/tutorials/Struts/. I get to step 8,
testing the application. Basically, you build a form and set an
action form method to forward success and failure to the original
page. Nothing special. When I hit submit, I get a blank page.
I've read a lot online and in my book, but can't figure out why it
won't forward. I'm thinking it may have to do with updates in the
struts build? Perhaps my book and the things I am reading online are
outdated?
Here are the pertinet parts of the files. Just trying to figure out
what I'm doing wrong. I have no idea how to troubleshoot this. There
are no logs, I haven't found a way to put in checks to see where it
fails etc. I'm just stumped.
web.xml - I used basically the default web.xml file from the
struts-blank application that comes with struts 1.4.2
struts-config.xml -
<struts-config>
<!-- ========== Form Bean Definitions ================= -->
<form-beans>
<form-bean name="submitForm"
type="hansen.playground.SubmitForm"/>
</form-beans>
<!-- ========== Action Mapping Definitions ============ -->
<action-mappings>
<action path="/submit"
type="hansen.playground.SubmitAction"
name="submitForm"
input="/submit.jsp"
scope="session">
<forward name="success" path="/submit.jsp" redirect="true"/>
<forward name="failure" path="/submit.jsp" redirect="true"/>
</action>
</action-mappings>
</struts-config>
Form class -
just gets and sets for each form element.
Action class -
package hansen.playground;
import javax.servlet.http.*;
import org.apache.struts.action.*;
public final class SubmitAction extends Action {
public ActionForward perform(ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) {
System.out.println("Got here!");
SubmitForm f = (SubmitForm) form; // get the form bean
// and take the last name value
String lastName = f.getLastName();
// Translate the name to upper case
//and save it in the request object
request.setAttribute("lastName", lastName.toUpperCase());
// Forward control to the specified success target
return (mapping.findForward("success"));
}
}
The meat of the Jsp page...
<html:form action="submit.do">
Last Name: <html:text property="lastName"/><br>
Address: <html:textarea property="address"/><br>
Sex: <html:radio property="sex" value="M"/>Male
<html:radio property="sex" value="F"/>Female<br>
Married: <html:checkbox property="married"/><br>
Age: <html:select property="age">
<htmlption value="a">0-19</htmlption>
<htmlption value="b">20-49</htmlption>
<htmlption value="c">50-</htmlption>
</html:select><br>
<html:submit/>
</html:form>