How to properly include the filter "org.apache.catalina.filters.SetCharacterEncodingFilter" in my Maven project?

Im using Maven 3.3 with JBoss 7.1.3.Final (Java 6). I want to include a filter in my web application so that all incoming request data is encoded as UTF-8. I added this to my web.xml file

<filter>
    <filter-name>CharsetFilter</filter-name>
    <filter-class>org.apache.catalina.filters.SetCharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>requestEncoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
</filter>
<filter-mapping>
        <filter-name>CharsetFilter</filter-name>
        <url-pattern>/*</url-pattern>
</filter-mapping>

and this dependence on Maven ...

            <dependency>
                <groupId>org.apache.tomcat</groupId>
                <artifactId>tomcat-catalina</artifactId>
                <version>7.0.0</version>
            </dependency>

but after deploying my application, I get the following error ...

WFLYCTL0186:   Services which failed to start:      service jboss.undertow.deployment.default-server.default-host./myproject.UndertowDeploymentInfoService: org.jboss.msc.service.StartException in service jboss.undertow.deployment.default-server.default-host./myproject.UndertowDeploymentInfoService: java.lang.ClassNotFoundException: org.apache.catalina.filters.SetCharacterEncodingFilter from [Module "deployment.myproject.war:main" from Service Module Loader]

What dependency do I need to enable for my application to deploy successfully?

+4
source share
1 answer

This question does not make sense in the first place.

, JBoss WildFly , , Apache Tomcat JBoss AS. UTF-8 JBoss WildFly /standalone/configuration/standalone.xml :

<servlet-container name="default">

default-encoding:

<servlet-container name="default" default-encoding="UTF-8">

JBoss AS 7.x, , UTF-8 JBoss AS 7.x(, , 6.x !) - /standalone/configuration/standalone.xml, <extensions> <management>:

<system-properties>
    <property name="org.apache.catalina.connector.URI_ENCODING" value="UTF-8" />
</system-properties>

/ , webapp , . :

@WebFilter("/*")
public class CharacterEncodingFilter implements Filter {

    @Override
    public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws ServletException, IOException {
        request.setCharacterEncoding("UTF-8");
        chain.doFilter(request, response);
    }

    // ...
}

webapp ( JAR), .

+4

Source: https://habr.com/ru/post/1662584/


All Articles