aspose file tools*
The moose likes Struts and the fly likes how to do Big Moose Saloon
  Search | Java FAQ | Recent Topics | Flagged Topics | Hot Topics | Zero Replies
Register / Login
JavaRanch » Java Forums » Frameworks » Struts
Bookmark "how to do "redirect-action"  to some action from within ActionSupport?" Watch "how to do "redirect-action"  to some action from within ActionSupport?" New topic
Author

how to do "redirect-action" to some action from within ActionSupport?

Michael Brown
Greenhorn

Joined: May 05, 2008
Posts: 27
Hy,

Can , please, someone help me with this:

How can I do a "redirect-action" to some action from within ActionSupport ?

I want to write an ActionSupport class that will insert some data in the DB and if succeeds , I want to redirect to some action set in this ActionSupport ( an action name, as String, is provided in this ActionSupport class ) and if not, just go to error.jsp

Can this be done, and how would I map this action in a strut.xml file ?

something like this:

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

You'd define a "success" result of the "redirectAction" type.
Michael Brown
Greenhorn

Joined: May 05, 2008
Posts: 27
Yes, If I want to use struts.xml

But I want to create redirect-action within code of my ActionSupport class...

How to do that?

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Why? There's almost never any reason to build a result dynamically in the code itself (and I suspect it's difficult enough to be impractical). What are you trying to do that you don't believe can't be done via normal means?
Michael Brown
Greenhorn

Joined: May 05, 2008
Posts: 27
First of all, I made a small mistake: I need just an ordinary "redirect" , not "redirect-action"

Why? There's almost never any reason to build a result dynamically in the code itself (and I suspect it's difficult enough to be impractical). What are you trying to do that you don't believe can't be done via normal means?


Let's say I have ActionSupport "a" whose view is "a.jsp" and on submit I "call" ActionSupport "b" that needs to insert some data in the DB and redirect to action "a" ( go to the beginning )

And what if I have N such "circles" for every table in the DB.
That way I would map N actions "a" + N actions "b" in the struts.xml

I want to make universal action "b" that will do the insertion of the data no matter how that data looks like , and redirect to some action that I specified in some String...
That way I don't need to map those N "b" actions in the struts.xml

This is just, of course, simplified version of what I'm doing...

David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

Use a dynamic result? You can use OGNL expressions in result declarations.

I don't understand what you're saying, though, and so far I don't see anything that would require generating dynamic configurations.
Michael Brown
Greenhorn

Joined: May 05, 2008
Posts: 27
Hi David,

Thank you very much for your answers!
I appreciate it!

Use a dynamic result? You can use OGNL expressions in result declarations.


This sounds like a solution to my problems...

I'll give it a try!
Pavel Kazlou
Ranch Hand

Joined: Sep 07, 2009
Posts: 33
Why writing to DB using struts ActionSupport? This class is used for request processing.
In your scenario ActionSupport B has no real meaning in terms of request. It just write something to DB.
So why don't you create DAO and use it inside your ActionSupport A to read/write from/to DB? I don't see any reason to using ActionSupport in such a strange manner.
David Newton
Author
Rancher

Joined: Sep 29, 2008
Posts: 12617

@Pavel: he said the DB work was being done from the action class, not how.
 
 
subject: how to do "redirect-action" to some action from within ActionSupport?