Struts Newbie - problems with Action Forwards

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">
<html:eek:ption value="a">0-19</html:eek:ption>
<html:eek:ption value="b">20-49</html:eek:ption>
<html:eek:ption value="c">50-</html:eek:ption>
</html:select><br>
<html:submit/>
</html:form>
 
S

Sudsy

Spivee said:
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.
<snip>

When in doubt, go back to the basics. I've written an article on Struts
flow which can be found here:
<http://www.sudsy.net/technology/struts-arch.html>
If that doesn't answer your questions then just wrap everying you have
into a war and send it to me off-ng. I'll install it in my dedicated
test environment (after exercising due diligence) and provide feedback.
Just so you know, the log destinations aren't always obvious. Under
Linux I use 'ls -lt' on the log directory to determine the files
which were most recently modified...
 
M

Martin Froment

The perform method is deprecated and no more available in the ActionServlet
controller of Struts 1.2.4 (not 1.4.2).

You must override the Action execute method in your SubmitAction class,
otherwise the superclass' execute method is called and it's returning a null
ActionForward (your blank page)...

public ActionForward execute(
ActionMapping mapping,
ActionForm form,
HttpServletRequest request,
HttpServletResponse response) throws Exception;

Martin.
 
S

Sudsy

Martin said:
The perform method is deprecated and no more available in the ActionServlet
controller of Struts 1.2.4 (not 1.4.2).

You must override the Action execute method in your SubmitAction class,
otherwise the superclass' execute method is called and it's returning a null
<snip>

Gosh darn! That's why it's always better to have multiple eyes on a
problem...
I read the original post assuming that the Action#execute method was
being invoked. Thanks for the correction/clarification, Martin!
 
S

Spivee

Thanks Martin, that was exactly the problem. I changed the perform
method to execute and that fixed the problem completely!



Martin Froment wrote:
The perform method is deprecated and no more available in the
ActionServlet
controller of Struts 1.2.4 (not 1.4.2).

You must override the Action execute method in your SubmitAction
class,
otherwise the superclass' execute method is called and it's returning
a null
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,755
Messages
2,569,537
Members
45,024
Latest member
ARDU_PROgrammER

Latest Threads

Top