package com.haha.action; 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 MyStrutsFilter implements Filter { public void destroy() { } public void doFilter(ServletRequest arg0, ServletResponse arg1, FilterChain arg2) throws IOException, ServletException { //核心 HttpServletRequest req=(HttpServletRequest) arg0; HttpServletResponse resp=(HttpServletResponse) arg1; //获取请求的路径 String path=req.getRequestURI(); System.out.println("请求的路径是:"+path); String actionName=path.substring(path.lastIndexOf("/")+1, path.lastIndexOf("do")+2); System.out.println("请求的Action名称是:"+actionName); //处理 AbsMyStrutsAction action=ActionFactory.getAction(actionName); /*if(actionName.equals("b.do")){ action=new BAction(); }*/ if(action!=null){ action.init(req, resp); action.run(); }else{ System.out.println("此"+actionName+"没有配置控制器"); } } public void init(FilterConfig arg0) throws ServletException { } }