What are best practices to follow while developing Struts2 application?
What are best practices to follow while developing Struts2 application?
Answer
Some of the best practices while developing Struts2 application are:
Always try to extend struts-default package while creating your package to avoid code redundancy in configuring interceptors.
For common tasks across the application, such as logging request params, try to use interceptors.
Always keep action classes java bean properties in a separate bean for code reuse and implement ModelDriven interface.
If you have custom interceptor that you will use in multiple actions, create interceptor stack for that and then use it.
Try to divide your application in different modules with namespace configuration based on functional areas.
Try to use Struts2 tags in result pages for code clarify, if needed create your own type converters.
Use development mode for faster development, however make sure production code doesn’t run in dev mode.
Use Struts2 i18n support for resource bundles and to support localization.
Struts2 provides a lot of places where you can have resource bundles but try to keep one global resource bundle and one for action class to avoid confusion.
struts-default package configures all the interceptors and creates different interceptor stacks. Try to use only what is needed, for example if you don’t have localization requirement, you can avoid i18n interceptor.
Disclimer: PCDS.CO.IN not responsible for any content, information, data or any feature of website.
If you are using this website then its your own responsibility to understand the content of the website