Win a copy of Microservices in Action this week in the Web Services forum!
  • 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 all forums
this forum made possible by our volunteer staff, including ...
Marshals:
  • Campbell Ritchie
  • Bear Bibeault
  • Devaka Cooray
  • Liutauras Vilda
  • Jeanne Boyarsky
Sheriffs:
  • Knute Snortum
  • Junilu Lacar
  • paul wheaton
Saloon Keepers:
  • Ganesh Patekar
  • Frits Walraven
  • Tim Moores
  • Ron McLeod
  • Carey Brown
Bartenders:
  • Stephan van Hulst
  • salvin francis
  • Tim Holloway

Is there a different way to configuring actions in struts2?  RSS feed

 
Greenhorn
Posts: 9
  • Mark post as helpful
  • send pies
  • 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
Chrome IntelliJ IDE Java
  • Mark post as helpful
  • send pies
  • 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: 9550
12
Linux Mac OS X Windows
  • Likes 1
  • Mark post as helpful
  • send pies
  • 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.
 
  • Post Reply Bookmark Topic Watch Topic
  • New Topic
Boost this thread!