我正在编写一个 servlet 过滤器。我想添加错误并将响应发送回请求来自的页面。
public void doFilter(ServletRequest request, ServletResponse response, FilterChain chain)
throws IOException, ServletException {
final HttpServletRequest servletRequest = (HttpServletRequest)request;
final HttpServletResponse servletResponse = (HttpServletResponse) response;
//add error and redirect the request to previous page
chain.doFilter(request, response);
}
我知道我们可以将响应重定向为
servletResponse.sendRedirect("/WebContent/Error.jsp");
请让我知道如何添加错误消息并将请求发回。
我想添加一些自定义错误消息。"Validation failed. Please try again".
提前致谢