java - Servlet filter confusion, response redirect isn't happening -
I have an authentication filter that prevents users from browsing on any pages where you have to log in to them. Will be:
public class authentication filter tool filter {private filter config FC; Private end string indexURL = "/index.xhtml"; Private Final String RegisterRuril = "/register/register.xhtml"; @ Override Public Zero Init (FilterConfig filterConfig) throws ServletException {this.fc = filterConfig; } @ Override Public Zero doFilter (ServletRequest request, ServletResponse response, FilterChain series) throws IOException, ServletException {HttpServletRequest req = (HttpServletRequest) request; HttpServletResponse resp = (HttpServletResponse) response; Http session session = req.getSession (); UserBean user = (UserBean) session.getAttribute ("userBean"); String request url = rect.getRequestURI (); System.out.println ("user" + user); If (user! = Null) {System.out.println ("username is" + user.getUsername ()); If (user.getUsername () == faucet = user.getUsername (). Ignore equals ("")) {System.out.println ("request url" is + requestUrl); If (! RequestUrl.equalsIgnoreCase (indexURL) & amp;; requestUrl.equalsIgnoreCase (registerUrl) & amp; Request URL. Star ("/ javax.faces.resource")) {// redirect back to indexpage system.out. Println ("The request is not for index index / register / resource, this is:" + requestUrl); Resp.sendRedirect (indexURL); }; }} And {resp.sendRedirect (indexURL); } Chain.dofilter (rake, resp); } @ Override Public Wide Dist () {}}
It is actually printing what I expect, but it is not redirecting, it is my log in information The last part is:
info: request is url / javax.faces.resource / jquery / jquery.js.xhtml information: user be.kdg.repaircafe.beans.UserBean@350af1bb information: user Name is empty Information: Request URL / javax.faces.resource / repaircafe_logo.png.xhtml Information: User may be.kdg.repaircafe.beans.UserBean@350af1bb information: User name is blank information: Request URL /welcome.xhtml information request is the URL for the directory / register / resources, it is: /welcome.xhtml serious: See error rendering [/welcome.xhtml] - & gt; I told you to redirect! Why are you doing this for me? After some debugging, I came to know that the debugger affects the series. Even after dopfilter () he re-directed the reaction, yet why is he sending me to welcome instead of the index?
I have decided to see it in another stackflow reply, if I return only hit after the redirect Then it will be stopped by filtering it forward.
Comments
Post a Comment