<package name="testPackage" extends="struts-default">
<action name="test-*" method="{1}" class="junit.test.action.TestAction">
<result name="success">/index.jsp</result>
</action>
</package>
这里test的创建管理由struts自己处理
public class TestAction extends ActionSupport {
private TestService testService ;
public void setTestService(TestService testService) {
this.testService = testService;
}
@Override
public String execute() throws Exception {
testService.printf() ;
return SUCCESS;
}
}
这里不会出现空指针异常,因为spring与struts的整合包会在IOC容器中查找可以注入set方法的bean并注入对象所以不会出现错误,但是不推荐这么做(建议action交给spring管理,并手动注入关系)
<action name="test-*" method="{1}" class="junit.test.action.TestAction">
<result name="success">/index.jsp</result>
</action>
</package>
这里test的创建管理由struts自己处理
public class TestAction extends ActionSupport {
private TestService testService ;
public void setTestService(TestService testService) {
this.testService = testService;
}
@Override
public String execute() throws Exception {
testService.printf() ;
return SUCCESS;
}
}
这里不会出现空指针异常,因为spring与struts的整合包会在IOC容器中查找可以注入set方法的bean并注入对象所以不会出现错误,但是不推荐这么做(建议action交给spring管理,并手动注入关系)