ZQTjava
ZQTjava
2012-08-16 20:37

struts1.X 的 filter 问题

  • struts

错误:标签处报错,错误如下
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条回答

为你推荐

换一换