I'm just discovering Struts2 and I have a problem with the web.xml
file.
It gives me an error near the filter tag:
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
The error says: Multiple annotations found at this line:
- Start tag of element <filter>
- The markup in the document following the root element must be well-
formed.
What is the problem? And how can I solve it?
Thank you!
Thanks Aleksander for your interest:
Here is my web.xml
file:
`<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<display-name>struts2example</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
</web-app>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>`
You are putting tags outside of the <web-app>
root tag. Put your <filter>
inside <web-app>
like that
<?xml version="1.0" encoding="UTF-8"?>
<web-app>
<display-name>struts2example</display-name>
<welcome-file-list>
<welcome-file>index.html</welcome-file>
<welcome-file>index.htm</welcome-file>
<welcome-file>index.jsp</welcome-file>
<welcome-file>default.html</welcome-file>
<welcome-file>default.htm</welcome-file>
<welcome-file>default.jsp</welcome-file>
</welcome-file-list>
<filter>
<filter-name>struts2</filter-name>
<filter-class>org.apache.struts2.dispatcher.FilterDispatcher</filter-class>
</filter>
<filter-mapping>
<filter-name>struts2</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
</web-app>
Also org.apache.struts2.dispatcher.FilterDispatcher
is deprecated since Struts 2.1.3, use org.apache.struts2.dispatcher.ng.filter.StrutsPrepareAndExecuteFilter
instead.