aspose file tools*
The moose likes Struts and the fly likes Frustration with struts part 2. Is it supposed to be this hard? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login


Win a copy of Spring in Action this week in the Spring forum!
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Frustration with struts part 2. Is it supposed to be this hard?" Watch "Frustration with struts part 2. Is it supposed to be this hard?" New topic
Author

Frustration with struts part 2. Is it supposed to be this hard?

Anthony McHenry.
Greenhorn

Joined: Mar 16, 2003
Posts: 9
So, I gave up on the previous project, and tried to make something simpler, same old blank page.
This time, I have just an ActionForward class:
public final class WelcomeAction extends Action
{
public ActionForward perform( ActionMapping mapping, ActionForm form, HttpServletRequest request, HttpServletResponse response )
{
request.setAttribute( "dateOfBirth", "05/24/1976" );
return ( mapping.findForward( "success" ) );
}
}
And in the struts-config file, I have a global forward and an action mapping:

<global-forwards
<forward name="welcome" path="/Welcome.do"/>
</global-forwards>

<action-mappings>
<action path="/Welcome" type="com.newsportal.WelcomeAction">
<forward name="failure" path="/pages/Error.jsp" />
<forward name="success" path="/pages/Welcome.jsp" />
</action>
</action-mappings>

And here is the web-form, index.jsp:

<%@ taglib uri="/tags/struts-logic" prefix="logic" %>
<logic:redirect action="/Welcome" />

and pages/Welcome.jsp:

<html>
<body>
<% out.println( "Welcome to the news portal" ); %>
<br/>
<% out.println( "Date of Birth: " + request.getParameter( "dateOfBirth" ) ); %>
</body>
</html>

Now, this is weird, I get a blank page most of the time, but not all of the time. Sometimes, I see a welcome message, but the dateOfBirth parameter is null.
Any help will be appreciated.
Thanks.
[ March 06, 2005: Message edited by: Anthony McHenry. ]
Craig Jackson
Ranch Hand

Joined: Mar 19, 2002
Posts: 405
Well, I think I see the problem.

You have to action-mappings pointing to the same path=/Welcome.



The first one, you are using the default ForwardAction, the second one you are using your custom action servlet, this is the one you are actually setting your DOB in the request object.
Anthony McHenry.
Greenhorn

Joined: Mar 16, 2003
Posts: 9
I am sorry about the confusion, I had actually commmented the first <action> entry out earlier, but didn't remove it in the post.
I double checked, and I still can't get it to work, but thanks for the help.
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
I'm thinking there's a disconnect between the version of the Struts tutorial you're following and the version of Struts you're using.

perform() was deprecated and is no longer part of Action, use execute.

logic:redirect doesn't have an action attribute, use one of forward, href, or page (in your case, one of forward='welcome' or href='\Welcome')

Unless you have a reason to be using an older version of Struts (ie: your company is still running Java 1.3 or something similarly awful) grab the latest version and bookmark the following:Struts home
Ray Stojonic
Ranch Hand

Joined: Aug 08, 2003
Posts: 326
I just looked at your other post, there is definitely a version conflict.
Anthony McHenry.
Greenhorn

Joined: Mar 16, 2003
Posts: 9
Thanks guys for all your help.
I used execute in my Action class instead of perform and it seems to be working fine...thanks
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Frustration with struts part 2. Is it supposed to be this hard?