a_jin_aaaaa
阿瑾啊
2019-03-21 16:37

请问这是什么原因,是关于servlet的包没有导入啥的吗?

  • java
  • tomcat
  • eclipse

在发布工程的时候com.bookonline.Filter.SetCharacterEncoding cannot be cast to javax.servlet.Filter

web.xml文件
<?xml version="1.0" encoding="UTF-8"?>
<web-app version="2.5" 
    xmlns="http://java.sun.com/xml/ns/javaee" 
    xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance" 
    xsi:schemaLocation="http://java.sun.com/xml/ns/javaee 
    http://java.sun.com/xml/ns/javaee/web-app_2_5.xsd">
<welcome-file-list>
    <welcome-file>index.jsp</welcome-file>
  </welcome-file-list>

   <filter>
    <filter-name>Set Character Encoding</filter-name>
    <filter-class>com.bookonline.Filter.SetCharacterEncoding</filter-class>
    <init-param>
            <param-name>encoding</param-name>
            <param-value>GB2312</param-value>
        </init-param>
        <init-param>
            <param-name>ignore</param-name>
            <param-value>true</param-value>
        </init-param>
  </filter>
  <filter-mapping>
        <filter-name>Set Character Encoding</filter-name>
        <url-pattern>/*</url-pattern>
    </filter-mapping>
  </web-app>

SetCharacterEncoding.java文件

package com.bookonline.Filter;
import javax.servlet.*;
import java.io.IOException;
import java.util.logging.Filter;
import java.util.logging.LogRecord;


public class SetCharacterEncoding implements Filter {
    private static  String  Encoding ;
    public void destroy() {
        // TODO Auto-generated method stub
        //System.out.println("---------exit  filter");
    }

    public void doFilter(ServletRequest arg0, ServletResponse arg1,
            FilterChain arg2) throws IOException, ServletException {
        arg0.setCharacterEncoding(Encoding);
        //System.out.println("----------"+Encoding);
        arg2.doFilter(arg0, arg1);
    }

    public void init(FilterConfig arg0) throws ServletException {
        Encoding = arg0.getInitParameter("encoding");
        //System.out.println("***************init filter");

    }

    public boolean isLoggable(LogRecord record) {
        return false;
    }
}
  • 点赞
  • 回答
  • 收藏
  • 复制链接分享

2条回答