SEVERE: Exception starting filter struts2 caused by web.xml file error in struts2

After the code comparison, mainly the comparison with the successful code, the problem was finally confirmed.

However, by solving such problems, I also learned some new knowledge.

问题:SEVERE: Exception starting filter struts2
Java.lang.ClassNotFoundException: org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

...........

This error occurs when the tomcat server starts, indicating that when tomcat starts, it will read web.xml and load the filter.

The solution process is as follows: I use the struts2+hibernate framework. When running the program, it always says There is no Action mapped for namespace / and action name sh. The problem, but it is indeed the correct configuration of struts.xml. At that time, I didn't consider it from web.xml, and I always thought that the configuration was correct. I did not check the problem from the tomcat startup information.

Inadvertently found tomcat error SEVERE: Exception starting filter struts2 . So I also carefully studied the filter principle, class loader, checked the console tomcat startup information and the meaning of each parameter in the information, etc., just wanted to consider this problem from the bottom.

Baidu a bit: 1. It may be that the jar package is wrong. But I have a normal program running the jar package without error, it should not be the problem. 2. It may be a build path problem. I put all the jar packages in the WEB-INFO/bin directory, it should be fine. <classpathentry kind="con" path="org.eclipse.jst.j2ee.internal.web.container"/> in the .classpath file means that the jar package in the WEB-INF/bin directory will be imported when the program is running, and the other One way is to manually add the jar package in the User library to the directory that is automatically loaded when the project is published: select the project, right-click the project and select Properties->Deployment Assembly->new: Add the created User library to the project, and the corresponding The .classpath file also changes.

Neither of the above are resolved. However, when testing the second solution, I considered closing other struts2 projects or deleting them from the tomcat server, because I was worried about whether other projects were configured incorrectly.

Finally, a correct struts2 project was run, and only the project was run in the tomcat server (right-click the tomcat server --> add and delete), and it ran normally. At this time, the project web.xml is compared with the web.xml of the wrong project, and the problem is found:

正确:org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter

错误:org.apache.struts2.dispacher.ng.filter.StrutsPrepareAndExecuteFilter

Is a spelling mistake of dispatcher, halo! After a few days, I finally got it done.

Summary: struts2 error first 1. Look at the tomcat startup information. 2. See if web.xml and struts.xml are correct. 3. Check whether the jar package in the bin directory is correct. 4. Add some test code, delete some code and see the running result. 5. Compare with running the correct project. 6. Think from the bottom up. The process of solving problems is also a process of improvement, and of course persistence is indispensable.

Guess you like

Origin http://43.154.161.224:23101/article/api/json?id=326368952&siteId=291194637