Apache Tomcat Maven 插件 uriEncoding 不适用于 https

Apache Tomcat Maven Plugin uriEncoding not working with https

我正在使用 tomcat7-maven-plugin 运行 我的应用程序 (tomcat7:运行)。我在没有 https 的配置中使用 <uriEncoding>utf-8</uriEncoding> 并且一切正常。但是一旦我添加了 https,编码就停止工作了。

当我在客户端发出这样的请求时:https://localhost:8443/ROOT/checkName?mediaName=%C3%A7%C3%A7

我在服务器上收到了这个:§Ã§

这是我的一些 pom.xml:

            <plugin>
                <groupId>org.apache.tomcat.maven</groupId>
                <artifactId>tomcat7-maven-plugin</artifactId>
                <configuration>
                    <warSourceDirectory>src/main/webapp</warSourceDirectory>
                    <path>/${project.warname}</path>
                    <warFile>target/${project.warname}##${maven.build.timestamp}-${project.name}-v${project.version}</warFile>
                    <uriEncoding>utf-8</uriEncoding>

                    <!-- HTTPS -->
                    <httpsPort>8443</httpsPort>
                    <keystoreFile>${user.home}/.mvnkeystore</keystoreFile>
                    <keystorePass>changeit</keystorePass>
                    <!-- HTTPS -->

                </configuration>
                <dependencies>
                    <dependency>
                        <groupId>mysql</groupId>
                        <artifactId>mysql-connector-java</artifactId>
                        <version>5.1.25</version>
                    </dependency>
                    <dependency>
                        <groupId>org.apache.tomcat.embed</groupId>
                        <artifactId>tomcat-embed-core</artifactId>
                        <version>${tomcat.version}</version>
                    </dependency>
                </dependencies>
            </plugin>

和web.xml:

    <security-constraint>
        <web-resource-collection>
            <web-resource-name>securedapp</web-resource-name>
            <url-pattern>/*</url-pattern>
        </web-resource-collection>
        <user-data-constraint>
            <transport-guarantee>CONFIDENTIAL</transport-guarantee>
        </user-data-constraint>
    </security-constraint>

如果我删除 https 标签,uriEncondig 会再次开始工作。

我认为您需要在服务器中配置 HTTPS 连接器。请参阅 here related question. The fact that you assign a value on the httpsPort property, means that you just enable the connector (with some defaults I guess) - as the plugin documentation suggests

您需要使用以下内容配置连接器:

<Connector port="443" protocol="HTTP/1.1"
           maxThreads="150" connectionTimeout="20000"
           SSLEnabled="true" scheme="https" secure="true"
           keystoreFile="conf/.keystore"
           keystorePass="changeit"
           clientAuth="false" sslProtocol="TLS"
           URIEncoding="UTF-8" compression="on"/>

希望对您有所帮助

这是 Apache Tomcat Maven 插件的报告错误 - MTOMCAT-264。 有空PR in github修复

您可以通过使用 serverXml 参数和文档中提到的警告来解决它。

serverXml: server.xml to use Note if you use this you must configure in this file your webapp paths.