servlet使用filter找不到filter class
这个是我的web.xml配置文件,配置了一个filter<filter><description></description><display-name>Characte...
这个是我的web.xml配置文件,配置了一个filter
<filter>
<description>
</description>
<display-name>CharacterEncodingFilter</display-name>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>cn.chenghui.bbs.utils.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
下面是我的filter类
package cn.chenghui.bbs.utils;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class CharacterEncodingFilter implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else
this.ignore = false;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
chain.doFilter(request, response);
}
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}
用的是tomcat6.0但是启动的时候总是提示说找不到CharacterEncodingFilter
tomcat的启动错误如下:
严重: Exception starting filter CharacterEncodingFilter
java.lang.ClassNotFoundException: cn.chenghui.bbs.utils.CharacterEncodingFilter
试了好多种方法了,都不行。哪位高人告诉我是怎么搞的啊? 展开
<filter>
<description>
</description>
<display-name>CharacterEncodingFilter</display-name>
<filter-name>CharacterEncodingFilter</filter-name>
<filter-class>cn.chenghui.bbs.utils.CharacterEncodingFilter</filter-class>
<init-param>
<param-name>encoding</param-name>
<param-value>UTF-8</param-value>
</init-param>
<init-param>
<param-name>ignore</param-name>
<param-value>true</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CharacterEncodingFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>
下面是我的filter类
package cn.chenghui.bbs.utils;
import java.io.IOException;
import javax.servlet.Filter;
import javax.servlet.FilterChain;
import javax.servlet.FilterConfig;
import javax.servlet.ServletException;
import javax.servlet.ServletRequest;
import javax.servlet.ServletResponse;
public class CharacterEncodingFilter implements Filter {
protected String encoding = null;
protected FilterConfig filterConfig = null;
protected boolean ignore = true;
public void init(FilterConfig filterConfig) throws ServletException {
this.filterConfig = filterConfig;
this.encoding = filterConfig.getInitParameter("encoding");
String value = filterConfig.getInitParameter("ignore");
if (value == null)
this.ignore = true;
else if (value.equalsIgnoreCase("true"))
this.ignore = true;
else
this.ignore = false;
}
public void doFilter(ServletRequest request, ServletResponse response,
FilterChain chain) throws IOException, ServletException {
if (ignore || (request.getCharacterEncoding() == null)) {
String encoding = selectEncoding(request);
if (encoding != null)
request.setCharacterEncoding(encoding);
}
chain.doFilter(request, response);
}
public void destroy() {
this.encoding = null;
this.filterConfig = null;
}
protected String selectEncoding(ServletRequest request) {
return (this.encoding);
}
}
用的是tomcat6.0但是启动的时候总是提示说找不到CharacterEncodingFilter
tomcat的启动错误如下:
严重: Exception starting filter CharacterEncodingFilter
java.lang.ClassNotFoundException: cn.chenghui.bbs.utils.CharacterEncodingFilter
试了好多种方法了,都不行。哪位高人告诉我是怎么搞的啊? 展开
3个回答
展开全部
首先确定你的cn.chenghui.bbs.utils.CharacterEncodingFilter
已经编译好了。然后把你编译好的class文件 放到你项目的 \WEB-INF\classes 下。
已经编译好了。然后把你编译好的class文件 放到你项目的 \WEB-INF\classes 下。
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
展开全部
路径配置!要么是*要么就是/…/…这样的配置,哪来的/*的配置?
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询