maven org.springframework.web.filter.CharacterEncodingFilter cannot be cast to javax.servlet.Filter

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/u014643282/article/details/80335874

maven项目解决办法:

   对于servlet-ap.jar 添加<scope>provided</scope> 即可解决。

    

<dependency>
            <groupId>org.apache.tomcat</groupId>
            <artifactId>tomcat-servlet-api</artifactId>
            <version>7.0.62</version>
            <scope>provided</scope>
</dependency>

或者是

<dependency>  
    <groupId>javax.servlet</groupId>  
    <artifactId>servlet-api</artifactId>  
    <version>2.5</version>  
    <scope>provided</scope>  
</dependency> 

阅读更多

cannot be cast to javax.servlet.Filter

12-28

我写了一个过滤器,配置在Web.xml文件中,启动程序时候就报以下错误:rnrnrnrn 严重: Exception starting filter sessionFilterrnjava.lang.ClassCastException: com.ghb.web.filter.SessionFilter cannot be cast to javax.servlet.Filterrn at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:255)rn at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:397)rn at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:108)rn at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:3800)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4450)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:722)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1045)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:443)rn at org.apache.catalina.core.StandardService.start(StandardService.java:516)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:710)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:583)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(Unknown Source)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(Unknown Source)rn at java.lang.reflect.Method.invoke(Unknown Source)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:288)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:413)rnrnrnrn类文件:rnrn package com.ghb.web.filter;rnrnimport java.io.IOException;rnrnimport javax.servlet.FilterChain;rnimport javax.servlet.FilterConfig;rnimport javax.servlet.ServletException;rnimport javax.servlet.ServletRequest;rnimport javax.servlet.ServletResponse;rnrnpublic class SessionFilter rnrn private FilterConfig config;rnrn public void destroy() rn // TODO Auto-generated method stubrn rnrn public void doFilter(ServletRequest req, ServletResponse resp,rn FilterChain chain) throws IOException, ServletException rn String enconding = config.getInitParameter("encoding");rn req.setCharacterEncoding(enconding);rn resp.setCharacterEncoding(enconding);rn chain.doFilter(req, resp);rn rnrn public void init(FilterConfig config) throws ServletException rn this.config = config;rn rnrnrnrnrnrn web.xml文件配置信息rn rn rn sessionFilterrn com.ghb.web.filter.SessionFilterrn rn encodingrn UTF-8rn rn rn rn sessionFilterrn /*rn rnrnrnrn 我之前用myeclipse的时候,是没有错的,我换到Eclipse后就报这个错了,网上搜了一大圈,有的说是包和rntomcat冲突,rnrn 这到底是什么原因啊rn

com.java.filter.FormFilter cannot be cast to javax.servlet.Filter

09-19

严重: Exception starting filter FormFilterrnjava.lang.ClassCastException: com.java.filter.FormFilter cannot be cast to javax.servlet.Filterrn at org.apache.catalina.core.ApplicationFilterConfig.getFilter(ApplicationFilterConfig.java:275)rn at org.apache.catalina.core.ApplicationFilterConfig.setFilterDef(ApplicationFilterConfig.java:422)rn at org.apache.catalina.core.ApplicationFilterConfig.(ApplicationFilterConfig.java:115)rn at org.apache.catalina.core.StandardContext.filterStart(StandardContext.java:4072)rn at org.apache.catalina.core.StandardContext.start(StandardContext.java:4726)rn at org.apache.catalina.core.ContainerBase.addChildInternal(ContainerBase.java:799)rn at org.apache.catalina.core.ContainerBase.addChild(ContainerBase.java:779)rn at org.apache.catalina.core.StandardHost.addChild(StandardHost.java:601)rn at org.apache.catalina.startup.HostConfig.deployDirectory(HostConfig.java:1079)rn at org.apache.catalina.startup.HostConfig.deployDirectories(HostConfig.java:1002)rn at org.apache.catalina.startup.HostConfig.deployApps(HostConfig.java:506)rn at org.apache.catalina.startup.HostConfig.start(HostConfig.java:1317)rn at org.apache.catalina.startup.HostConfig.lifecycleEvent(HostConfig.java:324)rn at org.apache.catalina.util.LifecycleSupport.fireLifecycleEvent(LifecycleSupport.java:142)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1065)rn at org.apache.catalina.core.StandardHost.start(StandardHost.java:840)rn at org.apache.catalina.core.ContainerBase.start(ContainerBase.java:1057)rn at org.apache.catalina.core.StandardEngine.start(StandardEngine.java:463)rn at org.apache.catalina.core.StandardService.start(StandardService.java:525)rn at org.apache.catalina.core.StandardServer.start(StandardServer.java:754)rn at org.apache.catalina.startup.Catalina.start(Catalina.java:595)rn at sun.reflect.NativeMethodAccessorImpl.invoke0(Native Method)rn at sun.reflect.NativeMethodAccessorImpl.invoke(NativeMethodAccessorImpl.java:39)rn at sun.reflect.DelegatingMethodAccessorImpl.invoke(DelegatingMethodAccessorImpl.java:25)rn at java.lang.reflect.Method.invoke(Method.java:597)rn at org.apache.catalina.startup.Bootstrap.start(Bootstrap.java:289)rn at org.apache.catalina.startup.Bootstrap.main(Bootstrap.java:414)rn2012-9-19 17:39:02 org.apache.catalina.core.StandardContext startrn严重: Error filterStartrn2012-9-19 17:39:02 org.apache.catalina.core.StandardContext startrn严重: Context [/Servlet] startup failed due to previous errorsrn2012-9-19 17:39:02 org.apache.catalina.startup.HostConfig deployDirectory

没有更多推荐了,返回首页