SSH(Spring + Struts + Hibernate)小試 之三
前面通過PlugIn我們實現了Spring Context的加載,不過僅僅加載Context并沒有什么實際
意義,我們還需要修改配置,將Struts Action交給Spring容器進行管理。下面將通過一個Regsit
實例加以說明。
首先準備好regist.jsp和login.jsp,在regist.jsp中 的form有name,password,password2,email域。
在struts-config.xml中添加配置:
<form-bean name="registForm" type="com.lzy.forum.form.RegistForm" />
<action path="/regist" name="registForm"
type="org.springframework.web.struts.DelegatingActionProxy"
validate="true" input="/regist.jsp" scope="request">
<forward name="failure" path="/regist.jsp" />
<forward name="success" path="/login.jsp" />
</action>
RegistForm,RegistAction按照原來Struts的方法去寫,我在RegistAction中加入了一個UserDAO對象
userDAO,這個對象由Spring注入。
<bean name="/regist" class="com.lzy.forum.action.RegistAction"
singleton="false">
<property name="userDAO">
<ref local="userDAO" />
</property>
</bean>
基本上SSH的架構已經完成,經確認后可以自己測試一下了。(完)