File APIs for Java Developers
Manipulate DOC, XLS, PPT, PDF and many others from your application.
http://aspose.com/file-tools
Win a copy of Clojure in Action this week in the Clojure forum!
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic

Struts Action to Servlet Chaining

 
Joshua Elkino
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
For the love of me i cannot figure out how to perform this.
If i set my <forward name="success" path="/home.do"/> this works perfectly. But once i try to change it so it runs my servlet such as <forward name="success" path="/MyServlet"/> I get an exception with ${pageContext.errorData.throwable.message} being blank. Nothing is being populated in my log files either!
If i try to remove the '/' then i get a missing '/' exception.

What am i doing wrong?

Thanks
 
Merrill Higginson
Ranch Hand
Posts: 4864
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
If you're going to forward to a servlet, you must specify redirect="true".
 
Joshua Elkino
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
I will try this out. 1 thing that worries me is that i don't want the user to know they visited that servlet.... thus is why i figured i would try to "forward" my request rather than redirect. Also should the redirect rule apply to my other mappings? Will this resolve my "this page has been submitted" warning when you refresh a page?
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The post-redirect-get pattern eliminates that.
 
Joshua Elkino
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
The <forward name="success" path="/MyServlet" redirect="true"/> forward did not work. I still get the exception page without a stack trace and when i do some simply syserrs in my action page, they all print until my last line return mapping.findForward("success");
 
Joshua Elkino
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
if i do a return new ActionForward("/MyServlet", true); instead, i see the redirect, but i hit the exception page as well. It looks like its failing before it gets to MyServlet because my first piece of code in either the post or get is an output that i never see in the logs.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
You might be able to use the regular forward mechanism from the action and return null to tell Struts not to do anything more.

It's unclear to me why you need to do any of this, though; is the servlet so complicated/archaic/whatever that it can't be made into an action, or its logic refactored out so it can be used by either?
 
Joshua Elkino
Ranch Hand
Posts: 91
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Thanks David. I was trying to separate some responsibility for development purposes, but i guess i could just plug everything in together.
 
David Newton
Author
Rancher
Posts: 12617
IntelliJ IDE Ruby
  • 0
  • Mark post as helpful
  • send pies
  • Quote
  • Report post to moderator
Separating stuff is a good idea, of course--it's just a question of how best to separate it. IMO separating into actions and servlets is a bad idea; the logic itself can be separated into some form of service.

This is one thing Inversion of Control (IoC)/Dependency Injection (DI) is great at--the implementation can be plugged in later, so the action could be written before the real service is implemented. In the meantime the action would use a dummy service. Or vice-versa--the service could be written and tested in isolation then used by an action written later.
 
Consider Paul's rocket mass heater.
  • Post Reply
  • Bookmark Topic Watch Topic
  • New Topic