• 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

Struts Action to Servlet Chaining

 
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
 
Ranch Hand
Posts: 4864
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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?
 
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
The post-redirect-get pattern eliminates that.
 
Joshua Elkino
Ranch Hand
Posts: 91
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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
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
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • 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
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
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.
 
reply
    Bookmark Topic Watch Topic
  • New Topic