im doing java web project using sessions , filters. in code second request onwards requests did not work. can tell me why?
here code filterrequest.java code
public void init(filterconfig filterconfig) throws servletexception { this.filterconfig = filterconfig; } public void dofilter(servletrequest req, servletresponse resp, filterchain chain) throws servletexception, ioexception { try{ httpservletrequest request = (httpservletrequest) req; httpservletresponse response = (httpservletresponse) resp; //system.out.println("inside filter.............." ); httpsession session = request.getsession(true); user u = null; if(session.getattribute("loggeduser")!=null){ u = (user) session.getattribute("loggeduser"); } if (u!= null || session.getattribute("loggeduser")!=null) { //system.out.println("user exits.." + u.getuname() ); chain.dofilter(req, resp); }else{ //system.out.println("user not exits.."); string message = "please login!"; request.setattribute("loginmsg", message); response.sendredirect(request.getcontextpath() + "/login2.jsp?loginmsg="); //response.sendredirect("login2.jsp"); // infine loop occures } }catch(exception e){ e.printstacktrace(); } }
Comments
Post a Comment