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

在发布工程的时候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个回答

包导入错误,如果是定义拦截器,需要实现的是 javax.servlet.Filter这个这个接口。

com.bookonline.Filter.SetCharacterEncoding cannot be cast to javax.servlet.Filter
不能转换为Filter
你实现的是import java.util.logging.Filter;
而需要实现的是 javax.servlet.Filter

javalearnNet
小黑鸣 回复阿瑾啊: import javax.servlet.*; import java.util.logging.Filter; 优先级问题
大约一年之前 回复
a_jin_aaaaa
阿瑾啊 那个,,import javax.servlet.*呢
大约一年之前 回复
Csdn user default icon
上传中...
上传图片
插入图片
抄袭、复制答案,以达到刷声望分或其他目的的行为,在CSDN问答是严格禁止的,一经发现立刻封号。是时候展现真正的技术了!
立即提问
相关内容推荐