0

I have the logonForm object in two action class (MemberAction, AccountOverviewAction). I want to make logonForm as session scope variable in struts2 in these two action class. But when open this view page, it throws below exception. Is there anything I have missing? On the other hand, i do not find struts2 web project mentioning about object as session scope example. I not mention session in http. If you know example, could you please give me the url?

    Unable to instantiate Action, memberAction, defined for 'membersite' in 
namespace
'/secure'com.opensymphony.xwork2.inject.ContainerImpl$MissingDependencyException
: No mapping found for dependency [type=com.awip.struts.actionform.LogonForm, 
name='session'] in private com.awip.struts.actionform.LogonForm 
com.awip.struts.action.MemberAction.logonForm. - action - 

LogonForm Bean

@Repository
@Scope("session")
public class LogonForm extends ActionSupport {

Action Class

public class MemberAction extends ActionSupport implements ServletRequestAware{

@Inject("session")
private LogonForm logonForm;

2 Action Class

public class AccountOveriewAction extends ActionSupport implements ServletRequestAware{

    @Inject("session")
    private LogonForm logonForm;

ApplicationContext.xml

<bean id="logonForm" class="com.awip.struts.actionform.LogonForm" scope="session"/>  // it seems useless of this line ???
<bean id="memberAction" class="com.awip.struts.action.MembersiteAction" />

struts.xml

<action name="membersite" method="displayMembersiteMain" class="memberAction">
            <result name="displayMembersiteMain" type="tiles">.membersite.Main</result>
AMMA
  • 121
  • 1
  • 10
  • where's your code? – msagala25 Sep 08 '17 at 01:04
  • My coding for session in struts2 may be wrong. As it is my first time to code struts. I have seen struts2 tutorial but I do not find the example of my case. – AMMA Sep 08 '17 at 01:53
  • Even if I find, e.g. [https://stackoverflow.com/questions/17244036/dependency-injection-in-struts2-accessing-session-scoped-beans?rq=1](https://stackoverflow.com/questions/17244036/dependency-injection-in-struts2-accessing-session-scoped-beans?rq=1) but it does not help. – AMMA Sep 08 '17 at 02:26
  • I have done another test. Even with ServletActionContext.getRequest(). the session variables also become disappeared and null after redirect to another page. – AMMA Sep 11 '17 at 08:01
  • Pointless, there's no a form bean in Struts2, you should create and instantiate objects yourself or via any DI framework like Spring. This question and answer was an attempt to implement session scoped beans in Struts2 using internal DI (not documented and discouraged yet). – Roman C Sep 11 '17 at 20:38

0 Answers0