Environment: JDK1.6
ide:myeclipse6.1
Jar:spring2.5.6,struts2-spring-plugin-2.2.1.jar, etc.
Steps:
After you create a new Web project, you need to make the following modifications
1, modify the Web.xml, add listener after the following:
<?xml version= "1.0" encoding= "UTF-8"?>
<web-app version= "2.4"
Xmlns= "HTTP://JAVA.SUN.COM/XML/NS/J2EE"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "Http://java.sun.com/xml/ns/j2ee
Http://java.sun.com/xml/ns/j2ee/web-app_2_4.xsd ">
<display-name>integration_web</display-name>
<welcome-file-list>
<welcome-file>index.jsp</welcome-file>
</welcome-file-list>
<listener>
<listener-class>org.springframework.web.context.ContextLoaderListener</listener-class>
</listener>
<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>
2, modify Applicationcontext.xml
...
3, modify Struts.xml
...
Note: If you leave Struts's action to spring to manage, you
The class configuration in the struts action is configured in spring:
<action name= "edit" class= "editaction" method= "Input" >
<result name= "Input" >/edit.jsp</result>
</action>
such as Applicationcontext.xml
<?xml version= "1.0" encoding= "UTF-8"?>
<beans xmlns= "Http://www.springframework.org/schema/beans"
Xmlns:xsi= "Http://www.w3.org/2001/XMLSchema-instance"
Xsi:schemalocation= "
Http://www.springframework.org/schema/beans
Http://www.springframework.org/schema/beans/spring-beans.xsd ">
<bean id= "Editservice" class= "Org.apache.struts.edit.service.EditServiceInMemory"/>
<bean id= "editaction" class= "Org.apache.struts.edit.action.EditAction" >
<property name= "Editservice" ref= "Editservice"/>
</bean>
</beans>
To
But here, I encountered an additional problem,
Serious when Tomcat starts: Error Listenerstart
After configuring Tomcat log4j, print out the error to let know that the original is applicationcontext.xml misplaced position.
Applicationcontext.xml need to be placed in the same level as the Web.xml directory.
The configuration of log4j in Tomcat is as follows:
Taking Tomcat5.5 as an example, tomcat5.5 does not automatically record log information by default and requires human configuration.
1. Create a property file in the common/classes of the Tomcat installation directory Log4j.properties
2, in the file to write the log information and the level of logging:
3, add Log4j.jar and Commons-logging.jar to the Common/lib directory in the Tomcat directory
4. Complete