Search code examples
javastruts2migrationstruts-1model-driven

Converting Action in Struts 1 to Struts 2 equivalent


I am trying to migrate an application from Struts 1 to Struts 2. In the migration process, I am facing the following issues:

  1. There is a Servlet which extends ActionServlet of Struts1. There are many overriden methods where by super is being called like process(), I would like to know its equivalent to convert to Struts2. As I am not getting its equivalent in StrutsPrepareAndExecuteFilter.

  2. I have converted all the form beans into ModelDriven beans and all the Actions to a class extending ActionSupport. Also made entry in struts.xml for it.

Please provide your silutions on the above two issues.


Solution

  • The process is running before the action executes. The purpose of overriding the framework classes is to change/extend the functionality. Most of modifications are related to the old framework and could be dropped. If you need to use some code that cannot be replaced in Struts2 then you should write a custom interceptor. This is a normal way to change/extend the functionality in Struts2 instead of classes overrides.

    You can read more about interceptors on the Struts docs site.

    You should be fine with your architecture, but ModelDriven could be replaced with injecting bean(s) into controller. See Nullpointerexception while setting a bean.

    Sometimes the scope of the bean is important, for example Struts1 uses a session scope by default. You can inject a sessionMap with the interceptor ant keep your objects in session if you need them or try to implement a session scoped bean like I did in this question.