3

In Struts2 we can define action without using action class in struts.xml as follows:

<action name="error">
    <result>/error.jsp</result>
</action>

In my application I am using struts2 convention. In this case how to avoid writing action classes. I have many scenarios where I just want to go to the page without using any business logic.

My result path is not just a JSP. I am using tiles. I am using code as follows:

@Action(value="homePage", results={@Result(name="success", location="homePage", type="tiles")})
Roman C
  • 49,761
  • 33
  • 66
  • 176
user995656
  • 123
  • 1
  • 14

1 Answers1

1

You can place you jsp to the WEB-INF/content this the default result path. Also you can change this using a constant struts.convention.result.path. Convention plugin creates configuration from all JSPs there. So if you have do-something.jsp under result path you can use /do-something in the browser to return this actionless result.

Roman C
  • 49,761
  • 33
  • 66
  • 176
  • My result path is not just a JSP. I am using tiles. I am using code as follows: @Action(value="homePage", results={@Result(name="success", location="homePage", type="tiles")}) – user995656 Aug 26 '14 at 19:08
  • @user995656: You should add this information into your OP. – Aleksandr M Aug 26 '14 at 19:36
  • @user995656 Convention plugin provides configuration via scanning action classes and packages and above scenario is possible if used with convention unknown handler provided by the plugin. But convention plugin is unable to scan your tiles configuration, doesn't create actionless results from it and unable to handle them. To make it working you should write all this code yourself. – Roman C Aug 27 '14 at 08:11
  • @RomanC : I got your point. I will write all this code myself. – user995656 Aug 27 '14 at 11:00