Tool version compatibility problem
Integrate Struts and Spring The basic idea is to Action The life cycle consists of the original Struts Manage , Leave it to Spring Manage
Correct
It's equivalent to that Li Sisi had to pick up guests by himself before , Now it's changed to the procuress to solicit , I'll give it back to Mr. Li for specific business Fuck Do With struts Module iterator label Based on , Integrate Step 1 : Run... First , See the effect , Learn again Step 2 : Imitation and troubleshooting Step 3 : struts.xml Step 4 : applicationContext.xml Step 5 : to configure web.xml Step 6 : struts2-spring-plugin-2.2.3.1.jar Step 7 : Test
The old rule , First download the runnable project in the upper right corner , Configure to run , After confirming availability , Then learn what steps have been taken to achieve this effect .
Test address http://127.0.0.1:8080/struts_spring/listProduct
After ensuring that the runnable project can run correctly , Then strictly follow the steps in the tutorial , Imitate the code again .
The imitation process inevitably has code differences , As a result, the expected operation results cannot be obtained , At this moment, by comparison The correct answer ( Runnable project ) And your own code , To locate the problem . In this way , Learning is effective , Troubleshooting is efficient , It can obviously improve the learning speed , Across all the barriers on the way to learning . It is recommended to use diffmerge Software , Compare folders . Put your own project folder , Compare with my runnable project folder . This software is awesome , You can know which two files in the folder are wrong , And clearly marked Here is a green installation and use tutorial : diffmerge Download and use tutorials
stay struts.xml Specify objectFactory The object factory is spring
That is action The creation of is left to spring conduct
<?xml version="1.0" encoding="UTF-8"?> <!DOCTYPE struts PUBLIC "-//Apache Software Foundation//DTD Struts Configuration 2.0//EN" "http://struts.apache.org/dtds/struts-2.0.dtd"> <struts> <constant name="struts.i18n.encoding" value="UTF-8"></constant> <constant name="struts.objectFactory" value="spring"/> <package name="basicstruts" extends="struts-default"> <action name="showProduct" class="productActionBean" method="show"> <result name="show">show.jsp</result> </action> <action name="addProduct" class="productActionBean" method="add"> <result name="show">show.jsp</result> </action> <action name="listProduct" class="productActionBean" method="list"> <result name="list">list.jsp</result> </action> </package> </struts>
stay WEB-INF Under the directory , Create file applicationContext.xml
to configure productActionBean notes : Don't put it in src below , Be sure to put it in WEB-INF Under the directory
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="productActionBean" class="com.how2java.action.ProductAction"> </bean> </beans>
<?xml version="1.0" encoding="UTF-8"?> <beans xmlns="http://www.springframework.org/schema/beans" xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" xmlns:aop="http://www.springframework.org/schema/aop" xmlns:tx="http://www.springframework.org/schema/tx" xmlns:context="http://www.springframework.org/schema/context" xsi:schemaLocation=" http://www.springframework.org/schema/beans http://www.springframework.org/schema/beans/spring-beans-3.0.xsd http://www.springframework.org/schema/aop http://www.springframework.org/schema/aop/spring-aop-3.0.xsd http://www.springframework.org/schema/tx http://www.springframework.org/schema/tx/spring-tx-3.0.xsd http://www.springframework.org/schema/context http://www.springframework.org/schema/context/spring-context-3.0.xsd"> <bean name="productActionBean" class="com.how2java.action.ProductAction"> </bean> </beans>
appoint Context monitor , The listener is tomcat When it starts, it will execute , For scanning WEB-INF/lib Whether there is... In the directory struts2-spring-plugin-2.2.3.1.jar
<web-app> <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> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
<web-app> <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> <dispatcher>FORWARD</dispatcher> <dispatcher>REQUEST</dispatcher> <url-pattern>/*</url-pattern> </filter-mapping> <listener> <listener-class>org.springframework.web.context.ContextLoaderListener</listener-class> </listener> </web-app>
For consolidation struts and spring Plug in for jar
This is included in the complete project download of this example jar
At this point struts Used ProductAction Has been made by spring Created
http://127.0.0.1:8080/struts_spring/listProduct
The official account of programming , Follow and get the latest tutorials and promotions in real time , thank you .
![]()
Q & A area
2020-02-19
Reception problem
1 One answer
forestfire Jump to the problem location Answer time :2021-01-15
You are a real cow bo, You can even say such coquettish words with fucking fine pages in your mouth
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2019-12-01
Why do I run the teacher's project also prompt java.lang.ClassNotFoundException: org.springframework.web.context.ContextLoaderListener
1 One answer
hz52 Jump to the problem location Answer time :2020-05-09
Spring What you need jar Did you pour all the bags in
The answer has been submitted successfully , Auditing . Please
My answer Check the answer record at , thank you
2019-08-28
Ask the webmaster for help ,Struts+Spring The data encapsulated in the object still exists after resetting
2019-04-21
Solve this and say I didn't add method , But there is clearly
2019-04-05
Example names vary
Too many questions , Page rendering is too slow , To speed up rendering , Only a few questions are displayed on this page at most . also 5 Previous questions , please Click to view
Please... Before asking questions land
The question has been submitted successfully , Auditing . Please
My question Check the question record at , thank you
|