• Post Reply Bookmark Topic Watch Topic
  • New Topic
programming forums Java Mobile Certification Databases Caching Books Engineering Micro Controllers OS Languages Paradigms IDEs Build Tools Frameworks Application Servers Open Source This Site Careers Other Pie Elite all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Jeanne Boyarsky
  • Ron McLeod
  • Paul Clapham
  • Liutauras Vilda
Sheriffs:
  • paul wheaton
  • Rob Spoor
  • Devaka Cooray
Saloon Keepers:
  • Stephan van Hulst
  • Tim Holloway
  • Carey Brown
  • Frits Walraven
  • Tim Moores
Bartenders:
  • Mikalai Zaikin

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

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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. ]
 
Ranch Hand
Posts: 405
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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.
 
Ranch Hand
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
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
Posts: 326
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I just looked at your other post, there is definitely a version conflict.
 
Anthony McHenry.
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Thanks guys for all your help.
I used execute in my Action class instead of perform and it seems to be working fine...thanks
 
Stinging nettles are edible. But I really want to see you try to eat this tiny ad:
a bit of art, as a gift, the permaculture playing cards
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic