1 Importing JAR Packages
- This article will give the address of the project at the end, you do not need to look urgently.
2 Configuring the Web. xml file
<?XML version= "1.0" encoding= "UTF-8"?><Web-appxmlns= "Http://xmlns.jcp.org/xml/ns/javaee"Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"xsi:schemalocation= "Http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"version= "3.1"> <!--Spring's listener - <Listener> <Listener-class>Org.springframework.web.context.ContextLoaderListener</Listener-class> </Listener> <Context-param> <Param-name>Contextconfiglocation</Param-name> <Param-value>Classpath*:applicationcontext.xml</Param-value> </Context-param> <Filter> <Filter-name>Opensessioninviewfilter</Filter-name> <Filter-class>Org.springframework.orm.hibernate4.support.OpenSessionInViewFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Opensessioninviewfilter</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping> <!--Struts2 's core filter - <Filter> <Filter-name>Struts2</Filter-name> <Filter-class>Org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter</Filter-class> </Filter> <filter-mapping> <Filter-name>Struts2</Filter-name> <Url-pattern>/*</Url-pattern> </filter-mapping> </Web-app>
- Among them, Struts2 's core filter does not have to say much.
- Spring's listener is the ServletContext listener, and when the project starts, Contextloaderlistener puts applicationcontext.xml into the domain properties of the ServletContext object.
- Because of the ServletContext object, the <context-param> node needs to be configured in Web. Xml.
3 Action.java
- Example: Classesaction.java
Packagecom.xuweiwei.action;Importcom.opensymphony.xwork2.Action;ImportCom.opensymphony.xwork2.ActionSupport;Importcom.xuweiwei.domain.Classes;ImportCom.xuweiwei.service.ClassesService;ImportOrg.apache.struts2.ServletActionContext;ImportOrg.springframework.context.annotation.Scope;ImportOrg.springframework.stereotype.Controller;ImportJavax.annotation.Resource;Importjava.util.List; @Controller ("Classaction") @Scope ("Prototype")//This note indicates whether it is a single case or multiple cases Public classClassesactionextendsActionsupport {@Resource (name=classesservice.service_name)PrivateClassesservice Classesservice; /*** Access to all class information *@return */ PublicString Classesinfos () {List<Classes> classeslist =Classesservice.classesinfos (); Servletactioncontext.getrequest (). SetAttribute ("Classeslist", classeslist); returnaction.success; }}
4 Project Address
- Https://github.com/xuweiweiwoaini/sshDemo
Struts2.3.34+hibernate 4.x+spring4.x integrates two parts under the surface