使用Filters
並且拒絕訪問jsp's
。
public class FilterMyJsp implements Filter{
public void doFilter(ServletRequest request, ServletReponse response,
FilterChain chain) {
HttpServletRequest req= (HttpServletRequest) request;
req.getRequestDispather("HandleError.jsp").forward(request,response);
}
}
的web.xml <filter> <filter-name>FilterMyJsp</filter-name> <filter-class>my.FilterMyJsp</filter-class> </filter> <filter-mapping> <filter-name>FilterMyJsp</filter-name> <url-pattern>*.jsp</url-pattern> </filter-mapping>
URL模式*
將這個過濾器應用到每個JSP的的。您可以設計HandleError.jsp
並顯示相應的錯誤消息,當用戶嘗試訪問其他頁面時將顯示該錯誤消息。