尝试用Filter 实现跨域时,提示is not assignable to 'javax,servlet.Filter'
实现跨域时,配置 web.xml时提示:
CORSFilter is not a concrete class
CORSFilter is not assignable to 'javax,servlet.Filter'
是什么原因?
-----------------------------web.xml---------------------------------------------
<?xml version="1.0" encoding="UTF-8"?>
<web-app xmlns="http://xmlns.jcp.org/xml/ns/javaee"
xmlns:xsi="http://www.w3.org/2001/XMLSchema-instance"
xsi:schemaLocation="http://xmlns.jcp.org/xml/ns/javaee http://xmlns.jcp.org/xml/ns/javaee/web-app_3_1.xsd"
version="3.1">
<!--display-name 显示名称-->
<display-name>wechat-baggio</display-name>
<servlet>
<servlet-name>WxServlet</servlet-name>
<!--<servlet-class>boilerWeChat.servlet.WxServlet</servlet-class>-->
<servlet-class>boilerWeChat.servlet.WxServlet</servlet-class>
<!--自动启动-->
<load-on-startup>1</load-on-startup>
</servlet>
<!-- url-pattern中配置的/WxServlet用于指定该Servlet的访问路径 -->
<servlet-mapping>
<servlet-name>WxServlet</servlet-name>
<url-pattern>/WxServlet</url-pattern>
</servlet-mapping>
<!--<welcome-file-list>-->
<!--<welcome-file></welcome-file>-->
<!--</welcome-file-list>-->
**<filter>
<filter-name>CORSFilter</filter-name>
<filter-class>boilerWeChat.servlet.CORSFilter</filter-class>
/**这里提示错误:boilerWeChat.servlet.CORSFilter is not a concrete class;boilerWeChat.servlet.CORSFilteris not assignable to 'javax,servlet.Filter'**/
<init-param>
<param-name>charset</param-name>
<param-value>UTF-8</param-value>
</init-param>
</filter>
<filter-mapping>
<filter-name>CORSFilter</filter-name>
<url-pattern>/*</url-pattern>
</filter-mapping>**
</web-app>
---------------CORSFilter.java -----------------------------------
public abstract class CORSFilter implements Filter {
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException,ServletException{
HttpServletResponse res=(HttpServletResponse)response;
res.setHeader("Access-Control-Allow-Origin", "*");
res.setHeader("Access-Control-Allow-Methods", "POST, GET, PUT, OPTIONS, DELETE");
res.setHeader("Access-Control-Max-Age", "3600");
res.setHeader("Access-Control-Allow-Headers", "x-requested-with, Content-Type");
res.setHeader("Access-Control-Allow-Credentials", "true");
chain.doFilter(request, response);
}
public void init(FilterConfig filterConfig){}
public void destory(){}
}
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
public abstract class CORSFilter implements Filter 你使用了抽象类去实现Filter肯定不行,请将abstract去掉