I've an ErrorFilter
which extends the spring GenericFilterBean
. I want to show an error page decorated with tiles if some error happens.
Is there any way to set a view name from the filter?
<filter>
<filter-name>errorFilter</filter-name>
<filter-class>com.abc.filter.ErrorFilter</filter-class>
<init-param>
<param-name>errorPage</param-name>
<param-value>/jsp/errorpage.jsp</param-value>
</init-param>
</filter>
This is the configuration in web.xml
and the doFilter
method in errorfilter
is the following:
public void doFilter(ServletRequest req, ServletResponse resp,
FilterChain chain) throws IOException, ServletException {
HttpServletRequest httpReq = (HttpServletRequest) req;
StringBuffer reqUrl = httpReq.getRequestURL();
try {
chain.doFilter(req, resp);
} catch (Exception ex) {
String requestRepresentation = createRequestRepresentation(req);
errorService.handleException(reqUrl.toString(), ex, requestRepresentation);
req.getRequestDispatcher(
getFilterConfig().getInitParameter("errorPage")).forward(req, resp);
} catch (Error er) {
errorService.handleError(reqUrl.toString(), er);
req.getRequestDispatcher(
getFilterConfig().getInitParameter("errorPage")).forward(req, resp);
}
}
The current errorpage is not decorated with tiles, so I want to decorate it with normal header and footer and call that view name from the filter.
Is it possible ?
Edit: Basically we want to be able to do something similar to Controller-method i.e. return "view name";
Already tried:
- httpResponse.sendRedirect("errorPageView"); does not work, it redirects to http://server/fooerrorPageView
- request.getRequestDispatcher("errorPageView").forward(request, response); also doesn't, similar as above (no http redirect, but gives the same "no such page error" content)