NutzCN Logo
问答 web.xml使用自带过滤器后 访问报404
发布于 2595天前 作者 qq_1a0ba638 1963 次浏览 复制 上一个帖子 下一个帖子
标签:
<filter>
    <filter-name>nutz</filter-name>
    <!-- <filter-class>com.yc.manager.filter.LoginFilter</filter-class> -->
    <filter-class>org.nutz.mvc.NutFilter</filter-class>
    <init-param>
      <param-name>exclusions</param-name>
      <param-value>*.js,*.gif,*.jpg,*.png,*.css,*.ico,*/static/*,/rs/*</param-value>
    </init-param>
    <init-param>
      <param-name>modules</param-name>
      <param-value>com.yc.manager.MainModule</param-value>
    </init-param>
  </filter>

LoginFilter继承了NutzFilter
之后访问

@At("loginjsp")
	@Ok("jsp:main.loginjsp")
	public void loginjsp() {
	}

这种lognjsp入口访问就会报404

web.xml种使用

<filter-class>org.nutz.mvc.NutFilter</filter-class>

就能正确访问

3 回复

LoginFilter的代码贴一下看看

public class LoginFilter extends NutFilter {
	
	@Override
	public void init(FilterConfig conf) throws ServletException {
		super.init(conf);
	}
	
	@Override
	public void doFilter(ServletRequest req, ServletResponse resp, FilterChain chain) throws IOException, ServletException {
		HttpServletRequest request = null;
		HttpServletResponse response = null;
		if (req instanceof HttpServletRequest) {
			request = (HttpServletRequest) req;
        }
		if(resp instanceof HttpServletResponse) {
			response = (HttpServletResponse) resp;
		}
		
		String requestUrl = request.getRequestURI();
        System.out.println(requestUrl);
        //注册和主页、登录不拦截
        if(requestUrl.equalsIgnoreCase("/Managerment/") || requestUrl.contains("/Managerment/register") || requestUrl.contains("/Managerment/login")) {
        	chain.doFilter(req, resp);
        	return;
        }

        IfmUser ifmUser = (IfmUser) request.getSession().getAttribute("loginUser");
        if(ifmUser!=null) {
            if(ifmUser.getStatus().equalsIgnoreCase("1")) {
                response.sendRedirect("http://localhost:8080/Managerment/loginjsp");
                request.setAttribute("msg", "该用户状态不可用,请联系管理员");
                return;
            }
            chain.doFilter(req, resp);
        } else {
            response.sendRedirect("http://localhost:8080/Managerment/loginjsp");
            return;
        }
		
	}

}

@wendal

chain.doFilter(req, resp);

全部改成

super.doFilter
添加回复
请先登陆
回到顶部