-1

我尝试启动Tomcat,它没有报错,但不幸的是前端接收到数据是乱码,我的过滤器可能无法发挥作用
在maven的项目输出目录下我发现web.xml是异常的
提示:无法解析spring.xml文件,无法解析字符编码过滤器
web.xml如下:

<servlet>
    <servlet-name>springmvc</servlet-name>
    <servlet-class>org.springframework.web.servlet.DispatcherServlet</servlet-class>
    <init-param>
        <param-name>contextConfigLocation</param-name>
        <!--springmvc-servlet.xml是servlet配置文件名称 -->
        <param-value>classpath:spring.xml</param-value>
    </init-param>
    <load-on-startup>1</load-on-startup>  <!-- 容器是否启动时加载servlet -->
</servlet>

<servlet-mapping>
    <servlet-name>springmvc</servlet-name>
    <url-pattern>/</url-pattern>
</servlet-mapping>
<!-- springMVC 配置结束 -->

<absolute-ordering></absolute-ordering>

<filter>
    <filter-name>characterEncodingFilter</filter-name>
    <filter-class>org.springframework.web.filter.CharacterEncodingFilter</filter-class>
    <init-param>
        <param-name>encoding</param-name>
        <param-value>UTF-8</param-value>
    </init-param>
    <init-param>
        <param-name>forceEncoding</param-name>
        <param-value>true</param-value>
    </init-param>
</filter>
<filter-mapping>
    <filter-name>characterEncodingFilter</filter-name>
    <url-pattern>/*</url-pattern>
</filter-mapping>

<!-- 配置静态资源 -->
<servlet-mapping>
    <servlet-name>default</servlet-name>
    <url-pattern>/static/js/*</url-pattern>
    <url-pattern>/static/css/*</url-pattern>
    <url-pattern>/static/img/*</url-pattern>
</servlet-mapping>


2_2019-10-20 171136.png

1

请粘贴文本,不要截图

Yujiaao · 10月20日

添加评论
0 个回答

撰写答案

推广链接