Hello.
As with a server error, when the user on the page is given this kind of error
show the user their own , another page. And in case of errors of a certain kind, one page; and for errors of a different kind, another . And how to catch such exceptional situations to redirect the user to another page?
Most interested in how to catch errors when the session on the server was destroyed.
I use JSF 2.0
|
1 answer
The standard error page can be written in web.xml:
<error-page> <error-code>404</error-code> <location>/errors/404.html</location> </error-page>
If we are talking about a specific error, then you can use the Servlet Filter ( example ), in which you can check whether the user has a session or not. And if not, send redirect to any of your pages.
Something like this:
public class LoginFilter implements Filter { // ... public void doFilter (ServletRequest request, ServletResponse response, FilterChain chain) throws IOException, ServletException { if (request.getSession(false) == null) { response.sendRedirect("/errors/my-error-page"); return; } chain.doFilter(request, response); } //........................... }
UPD
If you want to catch some specific exception that may appear on your page, then you can wrap the string chain.doFilter (request, response); in a try / catch block and in a catch, try to do something.
- Wow, how beautiful you can do! THANKS))) - Anton Mukhin
- Of course, it may turn out that a more complicated check is required than request.getSession (false). But this is up to you;) - cy6erGn0m
- Well, it goes without saying. The main thing is that I found a way to check the session and what is in it. And then you can pervert as you please. - Anton Mukhin
|