网上有许多相关的文档,参考资料里有详细的说明,这里只是把需注意的地方记录一下:
步骤:struts -----spring ---hibernate
第一步:struts
- public ActionForward execute(ActionMapping mapping, ActionForm form,
- HttpServletRequest request, HttpServletResponse response) {
- LoginForm loginForm = (LoginForm) form;// TODO Auto-generated method stub
- if ( username.equals ( "test" ) && password.equals ("test") ) {
- return mapping.findForward ( "indexForword" );
- } else {
- return mapping.getInputForward();
- }
- }
第二步:spring
注意:spring选择spring1,applicationContext.xml路径需注意下,在src下改为“/WEB-INF/classes/applicationContext.xml”,在web-inf下为"/WEB-INF/applicationContext.xml"
更改type="org.springframework.web.struts.DelegatingActionProxy"
plug-in放在message-resources下面(struts-config)
如有错误,到myeclipse找spring.jar包copy过去。
- <?xml version="1.0" encoding="UTF-8"?>
- <!DOCTYPE struts-config PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 1.2//EN" "http://struts.apache.org/dtds/struts-config_1_2.dtd">
- <struts-config>
- <data-sources />
- <form-beans >
- <form-bean name="loginForm" type="com.dreamity.struts.form.LoginForm" />
- </form-beans>
- <global-exceptions />
- <global-forwards />
- <action-mappings >
- <action
- attribute="loginForm"
- input="/login.jsp"
- name="loginForm"
- path="/login"
- scope="request"
- type="org.springframework.web.struts.DelegatingActionProxy">
- <forward name="failture" path="/login.jsp" />
- <forward name="success" path="/index.jsp" />
- </action>
- </action-mappings>
- <message-resources parameter="com.dreamity.struts.ApplicationResources" />
- <plug-in className="org.springframework.web.struts.ContextLoaderPlugIn">
- <set-property property="contextConfigLocation" value="/WEB-INF/classes/applicationContext.xml" />
- </plug-in>
- </struts-config>
第三步:hibernate
程序以四层结构来写,结构如附件。
https://p-blog.csdn.net/images/p_blog_csdn_net/bill1315/EntryImages/20081202/截图01.jpg
参考资料:
1,使用myeclipse集成struts,hibernate,spring的一个示例程序 http://www.cnblogs.com/xujiaci/archive/2007/10/11/920597.html
2,MyEclipse开发SSH(Struts+Spring+Hibernate)入门 http://blog.tanggaowei.com/2007/12/myeclipsesshstrutsspringhibernate.html