• 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

Is there a different way to configuring actions in struts2?

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
I have requirement to migrate legacy(Struts1.0) code to Struts2. If there are multiple methods in same action class, can we configure them in single action tag?

struts.xml


Here, I have single action i.e. "product" and single action class i.e. "ProductAction". So, can I configure both the methods (show,showErr) in single action tag?
 
Greenhorn
Posts: 14
1
IntelliJ IDE Chrome Java
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator
Personally I would consider Struts to be legacy and I would migrate to using Spring as soon as you can.

If you use the latest Spring boot for example, you can do away with all those nasty XML files which are cumbersome at best.  Then you can start to use annotations for all you configuration, dependency injection etc.

Just my oppinion though
 
Bartender
Posts: 9626
16
Mac OS X Linux Windows
  • Likes 1
  • Mark post as helpful
  • send pies
    Number of slices to send:
    Optional 'thank-you' note:
  • Quote
  • Report post to moderator

Baz Edwards wrote:Personally I would consider Struts to be legacy



Struts 2.5 is under active development, so I wouldn't call it "legacy".  Struts certainly isn't as popular as it used to be.

Baz Edwards wrote:
If you use the latest Spring boot



Spring Boot is a totally different animal.  It is a stand-alone application server and framework in one.  Struts is more akin to Spring MVC alone.  If one just needs a front controller, Struts will work just fine.  Struts can also be configured to use Spring to inject code into Struts actions, so they aren't necessarily exclusive.
I actually prefer XML configuration files to annotations as it is easier to find the configuration information in one place, rather than hunting around in Java source code.  

As for Abhishek's question, no, you cannot configure one action tag to correspond to multiple methods.  The purpose of the action tag is to map a particular web request to a particular method, so that wouldn't make sense.  
If you are looking to avoid writing a ton of XML, look at the Convention Plugin.  It allows one to specify a method name in a particular way and the plugin does the work of the working out the mapping.  It also supports a bunch of annotations to configure the various options available in the action XML tag.
 
Alas, poor Yorick, he knew this tiny ad:
a bit of art, as a gift, that will fit in a stocking
https://gardener-gift.com
reply
    Bookmark Topic Watch Topic
  • New Topic