How to configure web.xml when using Struts 2?

2019-07-30 13:26发布

问题:

I am New to Struts2. I don't understand that when i edit web.xml

  <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>

i get an error : Server Tomcat v8.0 Server at localhost failed to start.

What should i do?

回答1:

You should check if the class you wrote in the <filter-class> exists on the classpath, i.e. in the one of jars deployed with the application.

Read about web.xml used in Struts2 application. If you are using Struts 2.5.x the class should be

<filter-class>org.apache.struts2.dispatcher.filter.StrutsPrepareAndExecuteFilter</filter-class>

You might also want to know How to add Struts2 filter without web.xml.