Struts2 MVC底层的简单实现(4)

下面建立一个web的过滤器测试一下:
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;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestFilter implements Filter {
    @Override
    public void destroy() {
    }
    @Override
    public void doFilter(ServletRequest req, ServletResponse res,
            FilterChain chain) throws IOException, ServletException {
        HttpServletRequest request=(HttpServletRequest)req;
        HttpServletResponse response=(HttpServletResponse)res;
        request.getRequestDispatcher("/success.jsp").forward(request,response); 
    }
    @Override
public void init(FilterConfig filterConfig) throws ServletException {
    }
}

建立一个web的servlet测试一下:
import java.io.IOException;
import javax.servlet.ServletException;
import javax.servlet.http.HttpServlet;
import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpServletResponse;
public class TestServlet extends HttpServlet {
public void doGet(HttpServletRequest request,HttpServletResponse response)throws ServletException,IOException{
request.getRequestDispatcher("/success.jsp").forward(request, response);
    }
}

别忘了把解析xml的包导进去。
希望对你们理解框架有帮助!!!

内容版权声明:除非注明,否则皆为本站原创文章。

转载注明出处:http://www.heiqu.com/a26a5b19d2695f28bb654492bf46572e.html