• 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

Why does it hang when forwarding to the same controller using a different parameter?

 
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi I'm using Struts 1.2.9 with Tomcat 6.0.18 and Netbeans 6.5 and it freezes every time I forward to the same controller path but with a different parameter.
I'm using EventDispatchAction.

I got an update() method and a list() method.

The update() method forwards to post?list ( which uses list() ). Everytime it forwards there it gets stuck up. I'm wondering why or is there a solution to this? Any help woudl be greatly appreciated! Thanks in advance!

Ajushi
 
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
It'll be difficult to help without code or configs.
 
Ajushi Jones
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Hi David! Here's my code:



and here's my struts config:

 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd think you'd want to redirect to home.do after you're done, but I could be wrong.

In any case, the "update" method forwards to /home.do, not to post?list, as far as I can tell.

If you're not using Tiles you should consider removing the extra stuff related to Tiles, and at the very least remove the 30-line comment when posting the config so there's less to look at.
 
Ajushi Jones
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

David Newton wrote:I'd think you'd want to redirect to home.do after you're done, but I could be wrong.

In any case, the "update" method forwards to /home.do, not to post?list, as far as I can tell.

If you're not using Tiles you should consider removing the extra stuff related to Tiles, and at the very least remove the 30-line comment when posting the config so there's less to look at.



Sorry about the comments and I appreciate the suggestions, thanks! :)

I actually want the method to be forwarded to the user's posts list which is on http://mysite/post?list but it's giving me the StackOverflowException. Sorry I'm a newb at this.

Also, is it a good idea to forward a link to a JSP or must all links be forwarded to the controller? I'm thinking about creating a link that points to createPost.jsp

Thanks again!
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If you're getting a stack overflow then you're stuck in a recursive forward or something--I'd take a very close look at the flow logic, because something is almost certainly wrong.

IMO it's not a good idea to mix JSP and action URLs in the same application; most people *probably* agree with that, but I could be wrong. There's nothing *technically* wrong with it, but it could create more confusion than its worth, and if that page ever *does* end up having to be an action (like for data preparation or something) you'll have to change everything that refers to it, and anybody that had it bookmarked will be out of luck.
 
Ajushi Jones
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
An edit to the code above (I changed it anyway): should be:


I tried debugging it and it goes on a loop (weird!) at lines 83-86 above:



I'm really tempted to create a separate PostsListAction class but I want to see and learn most importantly if this problem can be solved and why is it this way. I still don't get it

About the creating a createPost.jsp (a page with from to create posts), how would you suggest I solve it? Should I add a new create() method that forwards to createPost.jsp and then the jsp's action is pointed at the add() method (http://mysite/post?add) ?
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
If nothing else I'd try making the parameter "complete", like "?list=list" or something like that--or check what the form submits to see the parameter value for the event.

I'm still pretty sure you don't want to forward to that request--if the page is refreshed the form will be submitted again. Search the web for the post-redirect-get pattern to see what I'm talking about.
 
Ajushi Jones
Greenhorn
Posts: 25
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Yeeeehaawww! "?list=list" worked!! I wonder why do I need to set the forward that way?

Ok, I'll research about the post-redirect-get pattern pattern. Are there any more patterns that I should be aware of?

I appreciate your effort David in helping me. Thanks a lot man, I've also learned some things
 
David Newton
Author
Posts: 12617
IntelliJ IDE Ruby
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I'd guess that without a value, a parameter might be ignored.

There are a million patterns to be aware of ;) Fortunately only a few of them are genuinely useful. *Un*fortunately which ones are useful depend on what we're doing--the trick is to recognize when they can be used to good effect.
 
Don't get me started about those stupid light bulbs.
reply
    Bookmark Topic Watch Topic
  • New Topic