日期:2014-05-18  浏览次数:20800 次

过滤器问题!请各位高手帮帮!好急
原意是在表单提交后通过过滤器解决中文乱码在另一个JSP页面中显示注册信息,是一本书上的代码!
在没有加过滤器的时候除了接收注册信息页面有代码后一切都很正常,加了过滤器servlet后,用JB2005编译出现错误信息:
  URL:   Unable   to   open   location:   Document   not   found   on   server

过滤器代码如下
package   filter;
import   java.io.*;
import   javax.servlet.ServletException;
import   javax.servlet.http.HttpServletResponse;
import   java.io.IOException;
import   javax.servlet.ServletRequest;
import   javax.servlet.ServletResponse;
import   javax.servlet.Filter;
import   javax.servlet.FilterChain;
import   javax.servlet.FilterConfig;

class   encodingFilter   implements   Filter{

                public   void   init(FilterConfig   filterConfig)throws   ServletException
                {
                }

                public   void   doFilter(ServletRequest   req,ServletResponse   res,FilterChain   chain)throws   IOException,ServletException{

                req.setCharacterEncoding( "gb2312 ");
                chain.doFilter(req,res);
}
                public   void   destroy()
                {
                }
}


WEB.XML中的设置如下
  <filter>
        <filter-name> encodingfilter </filter-name>
        <filter-class> filter.encodingFilter </filter-class>
    </filter>
    <filter-mapping>
        <filter-name> encodingfilter </filter-name>
        <url-pattern> /* </url-pattern>
    </filter-mapping>

注册页面userRegist1.jsp如下
<%@   page   contentType= "text/html;   charset=GBK "   %>
<html>
<head>
<title>
    新用户注册
</title>
</head>
<body   bgcolor= "#ffffff ">
<form   method= "POST "   action= "acceptUserRegist1.jsp "   name= "form1 "   >
新用户注册 <br/>
用户名(*): <input   type= "text "   name= "username "   size= "20 "> <br   />
密码(*): <input   type= "password "   name= "userpassword "   size= "30 "/>
性别: <input   type= "radio "   value= "男 "   checked   name= "sex "/> 男 <input   type= "radio "   name= "sex "   value= "女 "   /> 女 <br/>
出生年月: <input   type= "text "   name= "year "   size= "4 "