aspose file tools*
The moose likes Struts and the fly likes Why does it hang when forwarding to the same controller using a different parameter? Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "Why does it hang when forwarding to the same controller using a different parameter?" Watch "Why does it hang when forwarding to the same controller using a different parameter?" New topic
Author

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

Ajushi Jones
Greenhorn

Joined: Dec 11, 2007
Posts: 25
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
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

It'll be difficult to help without code or configs.
Ajushi Jones
Greenhorn

Joined: Dec 11, 2007
Posts: 25
Hi David! Here's my code:



and here's my struts config:

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Dec 11, 2007
Posts: 25
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Dec 11, 2007
Posts: 25
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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

Joined: Dec 11, 2007
Posts: 25
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
Rancher

Joined: Sep 29, 2008
Posts: 12617

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.
 
I agree. Here's the link: http://aspose.com/file-tools
 
subject: Why does it hang when forwarding to the same controller using a different parameter?