ZQTjava 2012-08-16 20:37
浏览 307
已采纳

struts1.X 的 filter 问题

错误:标签处报错,错误如下
The content of element type "web-app" must match "(icon?,display-
name?,description?,distributable?,context-param*,servlet*,servlet-mapping*,session-config?,mime-
mapping*,welcome-file-list?,error-page*,taglib*,resource-ref*,security-constraint*,login-
config?,security-role*,env-entry*,ejb-ref*)".

web.xml
<?xml version="1.0" encoding="GBK"?>

<!DOCTYPE web-app
PUBLIC "-//Sun Microsystems, Inc.//DTD Web Application 2.2//EN"
"http://java.sun.com/j2ee/dtds/web-app_2_2.dtd">


Struts Blank Application

<!-- Standard Action Servlet Configuration (with debugging) -->

action
org.apache.struts.action.ActionServlet

config
/WEB-INF/struts-config.xml


debug
2


detail
2

2

<!-- Standard Action Servlet Mapping -->

action
*.do

<!-- The Usual Welcome File List -->

index.jsp

<!-- Struts Tag Library Descriptors -->

/tags/struts-bean
/WEB-INF/struts-bean.tld


/tags/struts-html
/WEB-INF/struts-html.tld


/tags/struts-logic
/WEB-INF/struts-logic.tld


/tags/struts-nested
/WEB-INF/struts-nested.tld


/tags/struts-tiles
/WEB-INF/struts-tiles.tld

<!-- =======================上面的无关======================================= -->
<!-- 过滤器 -->

BookFilter
BookFilter
com.ssh.filter.BookFilter

encoding
GBK



BookFilter
/*

class Myfiler下红线 报错如下:

The type Myfilter must implement the inherited abstract method Filter.destroy()

filter 实体文件
package com.xubq.filter;

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 Myfilter implements Filter {
//定义一个encoding变量
public String encoding;
//重写doFilter()方法
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException {
// TODO Auto-generated method stub
// place your code here

        response.setCharacterEncoding(encoding);
        response.setContentType("text/html;charset="+encoding);
        request.setCharacterEncoding(encoding); 
        // pass the request along the filter chain
        chain.doFilter(request, response);
    }

public void init(FilterConfig fConfig) throws ServletException {
        // TODO Auto-generated method stub
        encoding = fConfig.getInitParameter("encoding");
    }

}

20分奉上 谢谢了。。

  • 写回答

1条回答 默认 最新

  • Dead_Knight 2012-08-16 21:18
    关注

    The type Myfilter must implement the inherited abstract method Filter.destroy()
    这个错误跟struts没有关系。错误信息已经很明显了,是因为你自定义的Myfilter类没有实现接口Filter中的destroy方法,在Myfilter类中增加以下代码段即可。
    public void destroy() {}

    本回答被题主选为最佳回答 , 对您是否有帮助呢?
    评论

报告相同问题?

悬赏问题

  • ¥15 HFSS 中的 H 场图与 MATLAB 中绘制的 B1 场 部分对应不上
  • ¥15 如何在scanpy上做差异基因和通路富集?
  • ¥20 关于#硬件工程#的问题,请各位专家解答!
  • ¥15 关于#matlab#的问题:期望的系统闭环传递函数为G(s)=wn^2/s^2+2¢wn+wn^2阻尼系数¢=0.707,使系统具有较小的超调量
  • ¥15 FLUENT如何实现在堆积颗粒的上表面加载高斯热源
  • ¥30 截图中的mathematics程序转换成matlab
  • ¥15 动力学代码报错,维度不匹配
  • ¥15 Power query添加列问题
  • ¥50 Kubernetes&Fission&Eleasticsearch
  • ¥15 報錯:Person is not mapped,如何解決?