java - How to get response from this filter? -
java - How to get response from this filter? -
the next servlet filter getting called, not able give right response. looping within filter itself. browser says,
the page isn't redirecting firefox has detected server redirecting request address in way never complete.
expenseauthenticationfilter.class
public class expenseauthenticationfilter implements filter { public expenseauthenticationfilter() { // todo auto-generated constructor stub } public void destroy() { // todo auto-generated method stub } public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception { seek { httpsession session = ((httpservletrequest)request).getsession(false); if (session == null){ system.out.println("inside login filter"); ((httpservletresponse) response).sendredirect("expensemanagementlogin.html"); } } grab (illegalstateexception ise){ system.out.println("session not yet created"); } chain.dofilter(request, response); } public void init(filterconfig fconfig) throws servletexception { // todo auto-generated method stub } }
expenseauthentication.class
public class expenseauthentication implements filter { public expenseauthentication() { // todo auto-generated constructor stub } public void destroy() { // todo auto-generated method stub } public void dofilter(servletrequest request, servletresponse response, filterchain chain) throws ioexception, servletexception, illegalstateexception{ seek { httpsession session = ((httpservletrequest) request).getsession(false); if (session == null ){ system.out.println("management filter"); ((httpservletresponse) response).sendredirect("expensemanagementlogin.html"); } } grab (illegalstateexception ise){ system.out.println("session not yet created"); } chain.dofilter(request, response); } public void init(filterconfig fconfig) throws servletexception { // todo auto-generated method stub } }
the web.xml
<filter> <filter-name>expenseauthentication</filter-name> <filter-class>com.pricar.hibernate.expenseauthentication</filter-class> </filter> <filter-mapping> <filter-name>expenseauthentication</filter-name> <url-pattern>*/expensedetailsmanagement.html</url-pattern> </filter-mapping> <filter-mapping> <filter-name>expenseauthenticationfilter</filter-name> <url-pattern>*/expensemanagementlogin.html</url-pattern> </filter-mapping>
the console log "http://localhost:8080/hibernate/expensedetailsmanagement.html" is
inside login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter within login filter
its not going expenseauthentication.class, goes expenseauthenticationfilter.class , loops within of it.
any suggestions!!
thanks!
when :
((httpservletresponse) response).sendredirect("expensemanagementlogin.html");
you're sending user right "expensemanagementlogin.html" page filtered expenseauthenticationfilter
.
here infinite loop.
as long user doesn't have session loop. , filter looping right there won't session. same thing sec filter. if filter sendredirect
path need filtered itself. unless have controls (here session creation), you'll have infinite loop.
as filter works on "expensemanagementlogin.html", why do redirection ?
java servlets servlet-filters
Comments
Post a Comment