1 HttpServletRequest req=(HttpServletRequest)request; 2 HttpServletResponse res=(HttpServletResponse)response; 3 4 String referer=req.getHeader("referer"); 5 //如果referer非空 6 if(referer!=null) //非空说明是内部forward 访问其他页面的 7 { //放行资源 8 chain.doFilter(request, response); 9 }10 //如果referer空 是直接 回车键访问 servlet的11 else12 {13 System.out.println("无法直接访问");14 response.setContentType("text/html;charset=utf-8");15 //警告 无法直接访问16 response.getWriter().write("" +17 "");21 22 }